Reputation: 3878
How is it possible to modify data from a partial when passing down to its sub-partial (in the context of assemble.io)? usage is something like this:
<!-- index.hbs -->
{{> heroImage src="img.jpg"}}
<!-- heroImage.hbs -->
<div>{{> responsiveImage srcset=src+"480w"}}</div>
<!-- responsiveImage.hbs -->
<img srcset={{srcset}} />
I can only pass the src
data but not using and modifying it, like src + "something"
or src"something"
.
Upvotes: 1
Views: 365
Reputation: 8993
If you wish to perform a string concatenation from within a mustache you will need to use a helper method and invoke it as a sub expression.
Such a helper method could be as simple as the following:
Handlebars.registerHelper('concat', function () {
return Array.prototype.slice.call(arguments, 0, -1).join('');
});
And your heroImage.hbs partial would use this helper in the following way:
<div>{{> responsiveImage srcset=(concat src " 480w")}}</div>
I have also created an example fiddle.
Upvotes: 1