Saturday, June 1, 2024
102
rated 0 times [  106] [ 4]  / answers: 1 / hits: 24201  / 9 Years ago, thu, july 2, 2015, 12:00:00

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.


More From » handlebars.js

 Answers
13

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.


[#65960] Tuesday, June 30, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
marisela

Total Points: 103
Total Questions: 105
Total Answers: 102

Location: Solomon Islands
Member since Fri, Oct 8, 2021
3 Years ago
;