-
Notifications
You must be signed in to change notification settings - Fork 2k
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
No way to directly process a block's inner text? #559
Comments
@benpusherhq we process content within block helpers in our helper-lib project by doing something like the following... Handlebars.registerHelper("markdown", function(options) {
var content = options.fn(this);
return Markdown.convert(content);
});
Is this what you're trying to do? |
That's almost what I was trying to do. The above suggestion processes the content as a Handlebars template first, then processes the result as markdown. I was aiming to process the inner block as markdown without first processing it as a template. There still doesn't seem to be a way (as far as I can tell) in Handlebars to access the inner block content without processing it. Since you can do this in vanilla Mustache, this seems like a potentially nice to have feature in Handlebars. Your suggestion is helpful though (and likely the preferred approach in many cases). Thanks! |
We have a similar use case where not having this functionality makes us sad. Would be nice if there was a way to define a raw block helper or something of the sort. |
@benpusherhq , @jezell So the goal here is to have a text representation of the block contents? What is the reason that you can't exec |
@kpdecker, correct me if I'm wrong but let's say you have this example:
What I'm referring to is getting the inner block contents without processing: i.e. "{{name}}" won't be substituted. Using |
That is correct. You would need to escape the mustache sequence if you want the literal.
Would render to something like
It's not as friendly as some sort of literal block notation but does allow you to mix and match. https://github.com/wycats/handlebars.js/blob/master/spec/basic.js#L6-L10 |
I have a similar case where I want to generate a styleguide possibly with a helper like this:
Where the And I would want it to render something like this as a resulting html: "Heading level 3" renders like this:<br>
<h3>Example heading</h3>
Sourcecode:<br>
<code>{{h3 "Example heading"}}</code> As you can see, even this simplified example adds plenty of stuff and then runs the raw code twice, once with normal fn(), and once with safestring. As I have not found a way to access the raw block code, I'm forced to write my styleguide codes without helpers, twice. 👎 So, I came here to either provide a real life usecase or for someone to suggest something obvious to solve my problem. Thanks :) |
Put something together that allows you to register raw block helpers. |
👍 to this as it makes it much saner to handle gettext implementations with Handlebars |
Closing this issue in favor of #573. |
(Related to: #353.)
It doesn't seem possible (or I can't figure out how) to implement this:
This is possible in vanilla Mustache via context functions (which get the inner text and a render callback). Context functions in Handlebars appear not to have this same signature and thus cannot be used for this purpose.
As there are workarounds to handle this, it is not a critical issue. I can also understand how this might not be handled "by design". That said, it would be nice to be able to process the inner text of a block via a registerHelper or a context function.
The text was updated successfully, but these errors were encountered: