In my template I render the following controller:
{{ render(controller('AppBundle:Widgets:myWidget')) }}
The WidgetsController as the convention dictates has the following:
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',
],
]);
}
}
And the myWidget.html.twig has the following:
{% for key,url in urls %}
<img src="{{ censor(url) }}" />
{% endfor %}
And the censor is defined via the following twig plugin:
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);
}
}
But I get the following Twig_Error_Syntax error:
Unknown "censor" function.
Do you fellows know why? Over my services.php I have these settings:
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/*');
So fellows do you have any sort of idea why?
Please try calling your extension like this
{{ url | censor }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With