Collect: access global variables in {{parseJSON}}

Say you have a partial view that uses a global variable:

<a href="/" class="logo"><img src="{{assets}}/logo.png"></a>

After you include partial with specific data, either {{parseJSON}}, or external JSON data:

{{#parseJSON '{"demo": true}'}}
{{>navigation}}
{{/parseJSON}}

all global variables, such as {{assets}}"killed" or at least overridden. Is there a chance to have access yet?

Thanks in advance!

+3
source share
2 answers

this is a known β€œproblem” with Handlebar particles in that the context inside the partial includes only the one transferred in the context and without the parent context, etc. You can learn more about the problem.

, Assemble {{partial}} , "" , . , , :

{{#parseJSON '{"demo": true}'}}
  {{partial "navigation"}}
{{/parseJSON}}

, partial .

, Handlebars (v2.0.0-alpha.1), . , .

, .

+4

:

{{#..}}
  {{>partial}}
{{/..}}

.

-1

All Articles