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
Assign variables in template #476
Comments
This goes against the premise of logicless templates and I don't think that this should be language-level construct. I think the recommended approach here would be to calculate this data in your context creation logic and pass it into the template. This allows for much more control as you have the full javascript language at your disposal rather than whatever subset is implemented in the template language.
|
I think this would be a good feature, not to introduce more logic to the template, but to pass in variables that is specific to that template. For example, 2 of my templates use the same partial. I would like to be able to pass some variables to that partial from the template level so that different things is output for the different template within the scope of the partial. |
+1 |
2 similar comments
+1 |
👍 |
👍 @kpdecker We can have loops, if statements, and a number of other logic constructs in templates. But apparently assigning a variable is too much logic in templates? I really don't get the reasoning behind that decision when the other default helpers contain way more logic than simply having the ability to assign a variable. |
+1 |
3 similar comments
+1 |
+1 |
+1 |
Something along these lines can be implemented using block parameters and is documented here: Since this is done in a separate namespace outside of the current context, it provides more consistent behavior over context assignment. |
the link does not work |
only the lord knows why some people think it's a good idea to use hbs at the server with node. |
why? |
Is it possible to assign a variable within a template and use it like variables from outside?
Example:
I want output a table, but 1 column is optional, depend on data (fields[].field2) exists or not.
In each row it is no problem to check, but how to check it for the header ?
At the moment i use a unsteady helper function "assign" which creates helpers.
But thats not a good solution and i cant use it in #if.
The text was updated successfully, but these errors were encountered: