I would like to know if it is possible to concat a variable with another string when loading a partial using Handlebars.
{{partial logos this ns=../ns nsr=../nsr id=id+"something"}}
I'd like to concat id+"something"
and storing it into id
, which would be sent to the template.
I'm using a custom helper to load partials (partial
) which merge this
with the options.hash
provided by handlebars.
The concat() method joins two or more strings. The concat() method does not change the existing strings.
Concatenation is the process of appending one string to the end of another string. You concatenate strings by using the + operator. For string literals and string constants, concatenation occurs at compile time; no run-time concatenation occurs. For string variables, concatenation occurs only at run time.
Description. The concat() function concatenates the string arguments to the calling string and returns a new string.
Here's an easier way. A helper named 'concat':
module.exports = function(){
var arg = Array.prototype.slice.call(arguments,0);
arg.pop();
return arg.join('');
};
To be used as:
{{>myPartial id=(concat "foo" myVar myOtherVar)}}
There is a way actually. I've tried with default partial loader ">", but I hope it should work with "partial" too.
You can write a helper like this
Handlebars.registerHelper( 'concat', function(path) {
return "/etc/path" + path;
});
and Call it like
{{> responsive-image src=(concat '/img/item-tire.png') alt="logo" }}
I hope that helps.
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