Twig default filter overrides defined template variables?

OYMjohn

New Member
I have the following construction in twig templates to create XML:\[code\]{# insuranceNode.xml.twig #}<insurance> <description></description> ... {% if dOptions|default(true) %} <options> {% for option in insurance.options %} {% include 'optionNode.xml.twig' with { 'option': option, 'dInsurances': false }%} {% endfor %} </options> {% endif %}</insurance>{# optionNode.xml.twig #}<option> <description></description> ... {% if dInsurances|default(true) %} <insurances> {% for insurance in option.insurances %} {% include 'insuranceNode.xml.twig' with { 'insurance': insurance, 'dOptions': false }%} {% endfor %} </insurances> {% endif %}</options>\[/code\]As you can see the two template partials include each other by default (\[code\]{% if dOptions|default(true) %}\[/code\] and \[code\]{% if dInsurances|default(true) %}\[/code\]). If not stopped properly it will cause an infinite loop and the application breaks with a maximum nested level fatal error. When partial optionNode is included in insuranceNode, the template var \[code\]dInsurances\[/code\] is set to false which should set the var \[code\]dInsurances\[/code\] in optionNode to false. Yet for some reason optionNode still prefers the default(true) for \[code\]dInsurances\[/code\] over the template variable set by insuranceNode. If the default() filter is removed from \[code\]dInsurances\[/code\] in the optionNode, it works as expected. Also when \[code\]dInsurances\[/code\] is set to true, it crashes as expected.Am I misunderstanding the mechanics of the default() filter? Or should the variable passed through the include directive be inherited in the template?Any help is much appreciated. Thanks in advance :)
 
Back
Top