I have a symfony controller returning this:
return $this->render('MyBundle:Default:index.html.twig', array('menu' => $menu));
menu
is a Menu
object.
In my template I want to call a method from the Menu class:
getHTML(string s1, String s2, array tab)
returning a HTML string.
How do I do that in the template? Is it even possible ?
You can get the current URL in Twig/Silex 2 like this: global. request. attributes. get('_route') .
In Twig templates variables can be accessed using double curly braces notation {{ variableName }} .
Yea, it's possible:
{{ menu.getHTML('first-string', 'second-string', ['tab1', 'tab2']) }}
Since Twig handles getters and issers automatically, you can omit the get
part:
{{ menu.HTML(...) }}
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