Skip to content

Parent path continues to drill down depth with multiple conditionals #583

Closed
@joshpangell

Description

@joshpangell

There is some confusion with depth. The parent path behaves differently when in a loop and when displaying a single piece of data. Additionally, the way that depth is created is not very clear.

The expected result of nesting one conditional within another is that the depth does not increase. If a loop was nested in a loop, then the increase of depth would make sense.

Here is an example of how depth works in a loop. When referencing the model value of options it is expected to use the ../ context to reach the root model. However, when nesting an additional (same model) conditional, it is unexpected to travel further down the depth to the ../../ context. Finally, once we've reached our final depth, the looped model still uses the root context (expected), but the same options model, when used as a value needs to have a context one level further down to ../../../, this is also unexpected.

{{#persons}}
    <li>
        {{#if ../options.show_first_name}} <!-- one level -->
            {{#if ../../options.show_last_name}}  <!-- two levels -->
                {{#if ../../../options.show_phone_number}} <!-- three levels -->
                    {{last_name}}, {{first_name}} {{phone_number}}<!-- first level -->
                    <br>Show phone number? {{../../../../options.show_phone_number}}<!-- four levels? -->
                {{/if}}
            {{/if}}
        {{/if}}
    </li>
{{/persons}}

Here is an example of a single model with nested conditionals. Like the looped model, each nested conditional is required to drill one level deeper in it's context. However, unlike the looped mode, once we reach the final depth, the options model can be used at the root depth.

{{#if options.show_first_name}}<!-- top level -->
    {{#if ../options.show_last_name}}  <!-- one level -->
        {{#if ../../options.show_phone_number}}<!-- two levels -->
            {{single.last_name}}, {{single.first_name}} {{single.phone_number}}<!-- top level -->
            <br>Show first name? {{options.show_first_name}}<!-- top level? -->
        {{/if}}
    {{/if}}
{{/if}}

Here is a fiddle with both of these examples outlined.

I believe the ideal solution for this would be to keep the depth all in the same context. As an example, this would be loop:

{{#persons}}
    <li>
        {{#if ../options.show_first_name}}
            {{#if ../options.show_last_name}} 
                {{#if ../options.show_phone_number}}
                    {{last_name}}, {{first_name}} {{phone_number}}
                    <br>Show phone number? {{../options.show_phone_number}}
                {{/if}}
            {{/if}}
        {{/if}}
    </li>
{{/persons}}

And this a single

{{#if options.show_first_name}}
    {{#if options.show_last_name}}
        {{#if options.show_phone_number}}
            {{single.last_name}}, {{single.first_name}} {{single.phone_number}}
            <br>Show first name? {{options.show_first_name}}
        {{/if}}
    {{/if}}
{{/if}}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions