Feature: contentFor block helper
See original GitHub issueLove the project. By far the easiest to get going so far for this node.js/express newbie.
The express-hbs project has a really neat feature I’d love to see added. I’m not well enough versed yet to create this and file a pull request. The contentFor helper is basically equiv to content placeholders in asp.net and very useful. Basically allows to adding content to a parent template/layout. Here’s the usage from express-hbs
layout.handlebars
{{{block "pageScripts"}}}
index.handlebars
{{#contentFor "pageScripts"}}
CONTENT HERE
{{/contentFor}}
Is this something we can get added, or would it be possible to get a helper function we can add as middleware?
Issue Analytics
- State:
- Created 11 years ago
- Reactions:3
- Comments:10 (3 by maintainers)
Top Results From Across the Web
block & contentFor - Ghost Handlebars Theme Helpers
{{/contentFor}} helper is used to access and populate the block definitions within the template that's being inherited. The inherited template is referenced ...
Read more >express-hbs - npm
Express handlebars template engine complete with multiple layouts, partials and blocks.. Latest version: 2.4.0, last published: a year ago.
Read more >ruby on rails - Rendering a content_for block in a helper
I'm trying to render the result of a content_for block through a helper. I have a template (HAML) and a layout as follows:...
Read more >Path Helpers - Buffalo – Rapid Web Development in Go
The contentFor helper takes a block of HTML and holds on to it using the given name. This block can then be used...
Read more >Helper Methods - Middleman
Template helpers are methods which can be used in your dynamic templates to ... take a block, allowing you to provide more complex...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just thought I’d chime in to say I was able to get the sample code above working in my application with a small modification:
I’m now able to define a {{{block “pageScripts”}}} in my layout page and fill it with content from my views inside of:
Thanks for the sample code to get me jump started!
Thanks! Glad this project is useful to you 😃
This feature is definitely something that’s perfect for helpers. Here’s one way you could go about doing this:
Let me know if this helps (or even works, I didn’t test it.)