-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to set a variable within a template #167
Comments
All lightncandy features should align with handlebars.js , I need time to look through handlebars.js to ensure how it support this or not. |
Please refer to handlebars-lang/handlebars.js#476 , so far handlebars.js do not support this. Another way to support this is implement |
Another way to do this is the 'private variable' feature of block helpers, #171 will deal with it. |
Please read the document README.md and search for |
While this issue has been closed for quite some time, I'd like to make a case for why it should be reopened. As of the latest implementation of handlebars.js, variable assignment can easily be achieved through helpers, both block and inline. For instance, the following works without the need for the explicit declaration of a global and/or private variable: function set( key, value, context ) {
context[key] = value;
} With the above helper, I could then assign a key to the context of my choosing, like so: {{set 'foo' 'bar' this}}
{{set 'foo' 'bar' someOtherObject}} When using handlebars.js, I frequently leverage helpers like this to set and then unset a temporary key on the given context. In LightnCandy, however, this is unachievable due to the imposed limitations on helpers. In keeping consistent with handlebars.js, especially when |
I'd also like to add that, in JavaScript, objects and arrays are always passed by reference, which is why my example above works, and I think this is the underlying theme of this thread. I feel like LightnCandy has missed the mark in this area. |
Not perfect, but less difficult :
tested with BUT FAILED with maybe helpers doesn't like spaces?.. Maybe i forget a compilation token? |
However.
|
Hi
I would like to write a helper that could set the value of a template variable within the template.
Something like:
{{#set "variableName"}} bla bla value for the variable{{anotherhelper "sdsds"}} {{/set}}
This is possible provided the $options argument of the helper closure is passed by reference.
Unless there is an easier way to do this that I have missed..
Thanks
C
The text was updated successfully, but these errors were encountered: