Невозможно использовать расширение ветки, когда я {визуализирую} контроллер
В моем шаблоне я отображаю следующий контроллер:
{{ render(controller('AppBundle:Widgets:myWidget')) }}
WidgetsController
В соответствии с требованиями конвенции имеет следующее:
namespace AppBundle\Controller;
use AppBundle\Constants\WidgetsConstants;
use AppBundle\Managers\DataFetch\WidgetsFetchingStrategy;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class WidgetsController extends Controller
{
public function myWidgetAction(){
return $this->render('widgets/myWidget.html.twig',[
'images'=>[
'http://example.com/myarticle'
'http://example.org/harem',
'http://example.org/tentacle',
],
]);
}
}
И myWidget.html.twig
имеет следующее:
{% for key,url in urls %}
<img src="{{ censor(url) }}" />
{% endfor %}
И censor
определяется с помощью следующего плагина twig:
namespace AppBundle\Twig;
class SanitizeArticlePhotosForList extends \Twig_Extension
{
public function getFilters()
{
return array(
new \Twig_SimpleFilter('censor', array($this, 'sensorAction')),
);
}
public function sensorAction($photoHtmlTag)
{
return str_replace(['tentacle','harem'],'censored',$photoHtmlTag);
}
}
Но я получаю следующую ошибку Twig_Error_Syntax
:
Unknown "censor" function.
Знаете ли вы, ребята, почему? Над моим services.php У меня есть следующие настройки:
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
// To use as default template
$definition = new Definition();
$definition
->setAutowired(true)
->setAutoconfigured(true)
->setPublic(false);
$this->registerClasses($definition, 'AppBundle\\', '../../src/AppBundle/*', '../../src/AppBundle/{Entity,Repository,Resources,Tests}');
// Changes default config
$definition->setPublic(true)->addTag('controller.service_arguments');
// $this is a reference to the current loader
//Loafing Controllers
$this->registerClasses($definition, 'AppBundle\\Controller\\', '../../src/AppBundle/Controller/*');
$this->registerClasses($definition, 'AppBundle\\Twig\\', '../../src/AppBundle/Twig/*');
Итак, ребята, у вас есть какие-нибудь идеи, почему?
3
1 answers
Пожалуйста, попробуйте позвонить по вашему внутреннему номеру следующим образом
{{url |цензор}}
2
Author: Alviaz, 2017-10-27 08:55:41