Question

as the title says, the problem is clear:

within the construction:

{{if is_completed == 1}}
 <div>
   <p>{{:#parent.parent.data.myproperty}}</p>
 </div>
{{/if}}

the parent properties are not visible!

I solved it by creating construction like:{{for movies ~myproperty=myproperty}} in parent loop, and ~myproperty is visible inside IF conditions, but what if I have several variables, what if I have many-level nesting data structure?

Was it helpful?

Solution

The {{if ...}} block adds another view, so means you need to add a .parent to step up through that view, as in: {{:#parent.parent.parent.data.myproperty}}

You can pass in variables as you said (~myproperty=...) and they will be visible to any depth of nesting.

Your variable can be an object too such as the current data object: ~myObj=#data:

{{sometag a=b ~myObj=#data}}
    ....
    {{:~myObj.myproperty}}
    ...
{{/sometag}}

so you don't need a separate variable for each property.

You can also access the top-level data object and drill down from there:

{{:~root.foo...myproperty}}.

And finally you can use #get("item") to step up through any number of {{if}} blocks and get the nearest "item" view (i.e. the item view for a repeating {{for ...}} block).

So you would write:

{{:#get("item").data.myproperty}}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top