SonataAdminBundle custom rendering of text fields in list

The solution: I’ve defined a custom html type in the config.yml for sonata_doctrine_orm_admin: sonata_doctrine_orm_admin: templates: types: list: html: MyBundle:Default:list_html.html.twig And created the custom list_html.html.twig template in which i do not escape HTML: {% extends ‘SonataAdminBundle:CRUD:base_list_field.html.twig’ %} {% block field%} {{value|raw}} {% endblock %} Now in the PostAdmin I can define the behaviour of the field … Read more

Comma separated list in twig

Don’t know about shortest but this could be clear. Try the following to add comma after all lines in the loop except the last one: {% for role in user.roles %} {{ role.name }} {% if not loop.last %},{% endif %} {% endfor %} Shorter version as suggested in comments: {% for role in user.roles … Read more

“Begins with” in Twig template

You can do that directly in Twig now: {% if ‘World’ starts with ‘F’ %} {% endif %} “Ends with” is also supported: {% if ‘Hello’ ends with ‘n’ %} {% endif %} Other handy keywords also exist: Complex string comparisons: {% if phone matches ‘{^[\\d\\.]+$}’ %} {% endif %} (Note: double backslashes are converted … Read more

Testing variable equality in twig

As far as I’m aware Twig supports all of the standard logical operators ==, !=, <, >, >=, and <=. Also, your first example {% if var1 = var2 %} does not check for equality, it assigns var2 to var1, you might want to change it to the comparison operator ==. The Twig sameas built … Read more

How reload Twig cache in Symfony 2

The most simple way, type the command : rm -rf app/cache/* The point is: all files in app/cache/ can be removed freely, they are regenerated when needed. If you really want to clear only twig cache : rm -rf app/cache/<environment>/twig Replace <environment> by dev, prod, or test according to your requirements.

Check if template exists before rendering

The service holding the twig engine if configured as default is ‘templating’. Inside your Controller do the following: if ( $this->get(‘templating’)->exists(‘AcmeDemoBundle:Foo:bar.html.twig’) ) { // … } The alternative would be catching exception the render() method throws like this: try { $this->get(‘templating’)->render(‘AcmeDemoBundle:Foo:bar.html.twig’) } catch (\Exception $ex) { // your conditional code here. } In a normal … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)