How to render a tree in Twig

I played around with domi27’s idea and came up with this. I made a nested array as my tree, [‘link’][‘sublinks’] is null or another array of more of the same. Templates The sub-template file to recurse with: <!–includes/menu-links.html–> {% for link in links %} <li> <a href=”https://stackoverflow.com/questions/8326482/{{ link.href }}”>{{ link.name }}</a> {% if link.sublinks %} … Read more

Extends parent blocks from embed template

As said in the comment, includes/embeds can’t alter blocks from their includer. That said there is an extension available that could solve your problem. This Deferred Twig Extension can be found here Basically the node postpones the execution of a said block. This way you can create a variable that holds all of your javascript … Read more

Twig variables in twig variable

I have twig variable html. To show it in twig template I do {{html}}. That variable look like {{region_top}}{{region_center}}. region_* is variables too. When twig parse my html variable he didn’t parse inner variables (regions). What can I should do? Twig takes your strings as a literal string, meaning you’ll see the content of the … Read more

What is the best way to notify a user after an access_control rule redirects?

So after quite a bit of research, I found the right way to do this. You’ll need to use an Entry Point service and define it in your firewall configuration. This method will not mess with your default page settings specified in your firewall config for logging in. The Code security.yml: firewalls: main: entry_point: entry_point.user_login … Read more

Twig iterate over object properties

You can first cast the object to array. You can build own filter casting your object to array. More about filters is available here: http://twig.sensiolabs.org/doc/advanced.html#filters It could then look like that: {% for key, value in my_object|cast_to_array %}

How to get config parameters in Symfony2 Twig Templates

You can use parameter substitution in the twig globals section of the config: Parameter config: parameters: app.version: 0.1.0 Twig config: twig: globals: version: ‘%app.version%’ Twig template: {{ version }} This method provides the benefit of allowing you to use the parameter in ContainerAware classes as well, using: $container->getParameter(‘app.version’);

tech