Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline helpers #8

Open
martinnormark opened this issue Sep 29, 2012 · 1 comment
Open

Inline helpers #8

martinnormark opened this issue Sep 29, 2012 · 1 comment
Labels
Milestone

Comments

@martinnormark
Copy link
Contributor

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

};
@martinnormark
Copy link
Contributor Author

Maybe Roslyn could be used to do this?

http://duoco.de/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant