Skip to content

Inline helpers #8

Description

@martinnormark

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');

};

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions