Getting the content of a block helper
In handlebarsjs you can use this keyword to retrieve the content between the block helper if you want to do processing on it. What' s the equivalent in our dotnet version?
this gives me back the instance of HandlebarsBlockHelper
{{bold}}Rex{{/bold}}
return new HandlebarsBlockHelper( (writer, options, context, parameters) => { // Access 'Rex' to bold? } );
That's not currently supported, but PR welcome of course. The original text of the template is currently thrown away during the process of converting from tokens to an expression tree.
Sent from my iPhone
On Mar 15, 2016, at 08:56, Breen [email protected] wrote:
In handlebarsjs you can use this keyword to retrieve the content between the block helper if you want to do processing on it. What' s the equivalent in our dotnet version?
this gives me back the instance of HandlebarsBlockHelper
{{bold}}Rex{{/bold}}
return new HandlebarsBlockHelper( (writer, options, context, parameters) => { // Access 'Rex' to bold? } );
— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/rexm/Handlebars.Net/issues/105
Ah thanks for the speedy reply @rexm !
I'm a little busy with work atm, but I will try and pull this down and take a look into it.
Longer answer - the point at which we still have a sequence of tokens, we can reconstitute the entire or any part of the text template* - each token can reproduce the text equivalent of itself - but once we start converting from tokens to expressions, the expressions do not store any context to say what combination of tokens (or text) were converted or collapsed into the resulting expression. So by the time we get from expression tree to compiled function, the context is long-gone.
*but any unusual whitespace is not preserved
I think the OP misunderstood how HandlebarsJS works. Keyword this inside block helper function would return current context. There is no way to access original uncompiled template in HandlebarsJS.
Thus I think this issue can be closed.
Closing this due to inactivity, and @imsedim indicating this is not actually a feature of handlebarsjs. Can reopen if this situation changes.
Bumping because I recently needed this and it is actually supported in HandlebarsJS: https://github.com/wycats/handlebars.js/issues/559
The referenced example in that issue is a markdown block helper.
Browsing the HandlebarsJS docs, I don't think one of the early block helper examples is possible (yet) with Handlebars.Net:
Handlebars.registerHelper('bold', function(options) {
return new Handlebars.SafeString(
'<div class="mybold">'
+ options.fn(this)
+ '</div>');
});
PR welcome!