handlebars-extend-block

add extend blocks to handlebars

Usage no npm install needed!

<script type="module">
  import handlebarsExtendBlock from 'https://cdn.skypack.dev/handlebars-extend-block';
</script>

README

handlebars-extend-block

Create extend blocks for handlebars allowing partials to inject text into parent elements. This is generally useful for script and style tags.

example

var handlebars = require('handlebars');
var extend = require('handlebars-extend-block');

handlebars = extend(handlebars);

Layout File

<head>
    <title>{{title}}</title>
    <link rel='stylesheet' href='/css/style.css'>
    {{{block "stylesheets"}}}
</head>

<body>
    {{{body}}}

    <hr/>
    post body
    <hr/>

    {{{block "scripts"}}}
</body>

Partial

{{#extend "stylesheets"}}
<link rel="stylesheet" href="/css/index.css"/>
{{/extend}}

let the magic begin

{{#extend "scripts"}}
<script>
document.write('foo bar!');
</script>
{{/extend}}