Is it possible to access Route parameter in twig template directly?
You can achieve it like this: {{ app.request.get(‘name’) }}
You can achieve it like this: {{ app.request.get(‘name’) }}
This is not a Silex problem (as of now) – Everything works perfectly on my side (Silex 1.2) Did you register the UrlGeneratorServiceProvider in your app ? in web/index.php: $app->register(new Silex\Provider\UrlGeneratorServiceProvider()); And you should really use path() instead of url()in this case : {{ path(‘home’) }}
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
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
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
This is easily reproductible : {% set nav = true %} {% if nav == “top” %} ok {% endif %} Displays ok. According to the documentation : Twig allows expressions everywhere. These work very similar to regular PHP and even if you’re not working with PHP you should feel comfortable with it. And if … Read more
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
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.
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