smfoote / tornado

HTML templates with asynchronous rendering, built with JavaScript.
http://smfoote.github.io/tornado/
Apache License 2.0
8 stars 3 forks source link

Turn sections params into helper context values #127

Closed smfoote closed 8 years ago

smfoote commented 9 years ago

Because Tornado does not allow you to look up the context, there needs to be a way to reference data outside of a sections's context. This can now be done with section params.

The section params are added to the helper context, and can be referenced by using the param name, prefixed with a $. For example:

{#data outerValue=myVal}
  {$outerValue}
{/data}

The helper context can now hold objects and arrays instead of just scalar values, and lookups on the helper context uses the same function as lookups on the normal context (which means functions are called and Promises are handled the same way).

prashn64 commented 9 years ago

Do we need the $?

If possible, could you use the normal {} syntax? If it's not in the context, then you can look at the helperContext.

smfoote commented 9 years ago

The $ is definitely not necessary from an implementation standpoint; we could build the helper context without it. However, I think it is important to have a clear delineation between the real context and the helper context, so that you can never accidentally use one when you meant to use the other.