Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change twig variable in include

Tags:

twig

symfony

I have two twig template : full_view.html.twig has this

{% set price2 = opttov.smoptprice|split('.') %}
...
{{ price2.0|default('E') }}
{{ price2.1|default('00') }}

i want to include the full_view.html.twig file in sale.html.twig and change the value of price2, to something like price2 = opttov.price|split('.'). i wrote in sale.html.twig this in for loop

{% for tov in item.tovar %} 
{% include 'DevFarmUGDvorBundle:Catalog:_full_view.html.twig' with {'opttov':tov, 'opttov.smoptprice': tov.price} %} 
{% endfor %}

doesnt work

like image 540
Hell Hush Avatar asked Sep 08 '26 06:09

Hell Hush


1 Answers

You can construct the parameter for the include in this manner:

{% for tov in item.tovar %} 
 {% 
  set opttov = {'smoptprice' : tov.price }
 %}

 {% include 'DevFarmUGDvorBundle:Catalog:_full_view.html.twig' 
     with     
    {'opttov':opttov } 
  %} 
{% endfor %}

Hope this help

like image 64
Matteo Avatar answered Sep 14 '26 11:09

Matteo