Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8044091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:07:04+00:00 2026-06-05T05:07:04+00:00

I have the following construction in twig templates to create XML: {# insuranceNode.xml.twig #}

  • 0

I have the following construction in twig templates to create XML:

{# 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>

As you can see the two template partials include each other by default ({% if dOptions|default(true) %} and {% if dInsurances|default(true) %}). 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 dInsurances is set to false which should set the var dInsurances in optionNode to false. Yet for some reason optionNode still prefers the default(true) for dInsurances over the template variable set by insuranceNode.

If the default() filter is removed from dInsurances in the optionNode, it works as expected. Also when dInsurances 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 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T05:07:05+00:00Added an answer on June 5, 2026 at 5:07 am

    From Twig documentation:

    The default filter returns the passed default value if the value is undefined or empty, otherwise the value of the variable

    So, if you pass false, twig will take default value.

    There are 2 fixes:

    1. Use “not” with negative values

      {% if not skipOptions %}
      ...
      'skipInsurances': true
      
    2. Use “defined” test: http://twig.sensiolabs.org/doc/tests/defined.html

      {% if dOptions is not defined or dOptions %}
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following construction: public static class Constants { public static class Foo
I have the following construction: for (String playerName: players) . I would like to
I have following plist: <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE plist PUBLIC -//Apple//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd>
I have to make this addRows method with some data, which needs following construction.
Like the title says, I have the following exception: Description: Event code: 3005 Event
I am new to Rails. I have following construction. Mainmenu in my project has
I have the following construction: typedef struct bucket { char *key; ENTRY *data; struct
I have an associative array (object) of the following construction var menu = new
This is a question regarding a very simple construction - I have the following
I have the following table: CREATE TABLE [dbo].[PartsWork]( [parts_work_id] [int] IDENTITY(1,1) NOT NULL, [experiment_id]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.