Support for inline Razor helpers, such as:
@helper ProductImage(ProductViewModel product) {
<img src="@product.ImageUrl" />
}
This requires a JavaScript function (the helper) to be registered at the top of the template function, right after the _tmpl array so that it can access it.
Since helpers usually appear at the bottom, the stock TextWriter passed around should be wrapped in a new class that takes input to a specific section. That way, at the end of the template you can easily add content that will go to the helpers section.
Example of the JavaScript template function
var tmpl = function(Model) {
var _tmpl = [];
var ProductImage = function (product) {
_tmpl.push('<img src=\"');
_tmpl.push(product.ImageUrl);
_tmpl.push(' />');
};
_tmpl.push('More of the template');
ProductImage(item);
_tmpl.push('The rest of the template');
};
Support for inline Razor helpers, such as:
This requires a JavaScript function (the helper) to be registered at the top of the template function, right after the
_tmplarray so that it can access it.Since helpers usually appear at the bottom, the stock
TextWriterpassed around should be wrapped in a new class that takes input to a specific section. That way, at the end of the template you can easily add content that will go to the helpers section.Example of the JavaScript template function