Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

symfony2 - twig - how to render a twig template from inside a twig template

Tags:

twig

symfony

I have a xxx.html.twig file which shows a page, but when I want to refresh the page with different data and just update it with new data, I have a select and a submit button for it. The thing is that I don't know how do I call an action in the controller which I pass parameters to from my twig and call for new data and then I render the same twig template again with new parameters.

How do I do so?

like image 605
Alon Avatar asked Jul 30 '12 07:07

Alon


2 Answers

Here are a few different ways:

{{ render(app.request.baseUrl ~ '/helper/test', {"hostid2": hostid } ) }}

or

{% include 'MyCoreBundle:Helper:test.html.twig' with {"hostid2": hostid } only %}

or

{% render controller("MyCoreBundle:Helper:test", {'hostid2': hostid}) %}
like image 177
someuser Avatar answered Oct 10 '22 23:10

someuser


Symfony 2.1:

{% render 'YourBundle:YourController:yourAction' with {'var': value} %}

Symfony 2.6+:

{{ render(controller('YourBundle:YourController:yourAction', {'var': value})) }}

And, of course, read the documentation.

like image 33
Vitalii Zurian Avatar answered Oct 11 '22 01:10

Vitalii Zurian