-
Notifications
You must be signed in to change notification settings - Fork 338
Description
I understand that the current implementation of JsRender treats each block tag as essentially its own view. This means that if you have a variable accessible to the main template, it is no longer accessible to the block:
{{!-- called with {foo: 'bar', baz: [1, 2, 3]} --}}
{{: foo}}
{{for baz}}
{{: foo}} {{!-- error, can't find it--}}
{{/for}}
I know there are ways around this, either by using #parent.parent.data
or passing variables in explicitly. However, it seems unintuitive to have to do this every time you open a for
block. Just based on experience with pretty much every programming language in existence, a simple block does not lose all access to parent variables - it's not like using an external template, which would be more akin to a new function with new local scope.
I also understand that this is due to JsRender's (rather odd, IMO) decision to only "work" on a single data item at once and all normal accesses would be properties of that item. But we could at least attach the parent item's properties as helper objects, for example, so they could be easily accessed as ~variables without having to explicitly declare them for every single block.