I am trying to assign values within a template, the idea is to do something like this:
{{#if author}} {{className = 'classA'}} <- trying to implement this line. {{else}} {{className = 'classB'}} {{/if}} <div class={{className}}></div>
Is it possible to do so without registerHelper?
A Handlebars helper call is a simple identifier, followed by zero or more parameters (separated by a space). Each parameter is a Handlebars expression that is evaluated exactly the same way as described above in "Basic Usage": template {{firstname}} {{loud lastname}}
To create custom helpers in your theme just create a helpers. js file in the theme directory; here you can add your custom helper functions. Below there is an example of code which creates two super simple custom helpers which accept one argument: /* * Custom theme helpers for Handlebars.
You can use the unless helper as the inverse of the if helper. Its block will be rendered if the expression returns a falsy value. If looking up license under the current context returns a falsy value, Handlebars will render the warning. Otherwise, it will render nothing.
I needed this solution solved in the same way the original poster expected. Therefore I created a helper function to do this for me.
function setVariable(varName, varValue, options){ options.data.root[varName] = varValue; };
Contained within the options in the helper, is the data block, with the root of the helper variables.
I placed my variable within the root object, either assigning or overwriting with the value provided.
The helper in html looks a lot like this.
{{setVariable "thisVar" "Contents Here"}} <div> {{thisVar}} </div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With