# How the block and contentFor helpers work in Ghost

Explainer · Norbert · Updated 12 Nov 2026 · 2 min read

Source: https://brightthemes.com/blog/ghost-block-helper

{{{block}}} leaves a named slot in a Ghost layout, and {{#contentFor}} fills it from a template. Use them to add scripts, classes or meta tags to one kind of page only.

Most Ghost themes have one layout, `default.hbs`, with the HTML every page shares. Templates such as `post.hbs` or `page.hbs` fill it with their content. The `{{{block}}}` and `{{#contentFor}}` helpers let a template put content in other places of that layout too: a script before `</body>`, a class on `<body>`, a tag in `<head>`.

## The block helper

`{{{block "name"}}}`, with three curly braces, leaves a named slot in a layout. Give each slot a unique name:

```hbs
<!-- default.hbs -->
<body>
  ...
  {{{block "scripts"}}}
</body>
```

When no template fills the slot, Ghost leaves it out, so a layout can have as many slots as you like.

## The contentFor helper

`{{#contentFor "name"}} … {{/contentFor}}` fills a slot. It goes in a template that uses the layout, which the template names with `{{!< default}}` on its first line:

```hbs
<!-- page.hbs -->
{{!< default}}

{{#contentFor "scripts"}}
  <script>
    runPageScripts();
  </script>
{{/contentFor}}
```

When Ghost renders a page with this template, the script appears where `{{{block "scripts"}}}` is in `default.hbs`. Pages that use other templates don't get it.

## The body helper

`{{{body}}}` works like a block that every template fills without `contentFor`: it is where the rest of the template goes.

```hbs
<!-- default.hbs -->
<div class="site-wrapper">
  {{{body}}}
</div>
```

```hbs
<!-- post.hbs -->
{{!< default}}

<article class="post-content">
  {{content}}
</article>
```

> [!NOTE]
> A file with `{{{block}}}` slots is a layout, and Ghost can't use it directly as a template. `post.hbs`, `page.hbs` and `index.hbs` can use a layout and fill its slots, but they can't hold slots of their own.

## When to use them

- **Scripts for one kind of page.** Load a script only where it's needed, for example a [table of contents](https://brightthemes.com/widgets/toc) or share buttons on posts, so other pages stay light. The [featured posts slider](https://brightthemes.com/blog/ghost-featured-posts-slider) tutorial loads its library this way, on the homepage only.
- **Classes on the body or other tags.** Add a slot inside an attribute, such as `<body class="{{body_class}} {{{block "body_class"}}}">`, and fill it from a template to style that template differently.
- **Tags in the head.** Leave a slot in `<head>` and fill it from a template, for example with a preload for that template's hero image or a meta tag only those pages need.
- **Optional sections.** Leave a slot for an ad unit or a banner in the layout, and fill it only in the templates that should show it, inside a `{{#match}}` or `{{#if}}` when it depends on a condition.

Because the content stays in the template that needs it, the layout stays the same for every page and is easier to maintain. For code you add in Ghost Admin rather than in the theme, use [code injection](https://brightthemes.com/blog/ghost-code-injection) instead. For how layouts, templates and partials fit together, read [Ghost theme structure, explained](https://brightthemes.com/blog/ghost-theme-structure). To add conditions, see [how the match helper works](https://brightthemes.com/blog/ghost-match-helper).
