Edit on GitHub

Content Blocks


Content blocks are text, HTML or Markdown blocks that can be edited separately from the page or layout. They are designed to hold static content only and support basic templating variables. Partials are more flexible and should be used for generating dynamic content.

Content blocks files reside in the /content subdirectory of a theme directory. The following extensions are supported for content files:

Extension Description
htm Used for HTML markup.
txt Used for plain text.
md Used for Markdown syntax.

The extension affects the way content blocks are displayed in the backend user interface (with a WYSIWYG editor or with a plain text editor) and how the blocks are rendered on the website. Markdown blocks are converted to HTML before they are displayed.

Rendering content blocks

Use the {% content 'file.htm' %} tag to render a content block in a page, partial or layout. Example of a page rendering a content block:

url = "/contacts"
<div class="contacts">
    {% content 'contacts.htm' %}

Passing variables to content blocks

Sometimes you may need to pass variables to a content block from the external code. While content blocks do not support the use of Twig markup, they do support using variables with a basic syntax. You can pass variables to content blocks by specifying them after the content block name in the {% content %} tag:

{% content 'welcome.htm' name='John' %}

Inside the content block, variables can be accessed using singular curly brackets:

<h1>This is a demo for {name}</h1>

More information can be found in the Markup guide.

Global variables

You may register variables that are globally available to all content blocks with the View::share method.

View::share('site_name', 'Winter CMS');

This code could be called inside the register or boot method of a plugin registration file. Using the above example, the variable {site_name} will be available inside all content blocks.

Keep informed

Sign up to our newsletter to receive updates on Winter CMS releases, new features in the works, and much more.
We'll never spam or give this address away.

Latest blog post

Winter v1.2.1 is now available

Published October 19, 2022

View this post Read all posts

Latest Winter CMS release


Released October 20, 2022
14 UX/UI Improvements, 25 API Changes, 33 Bug Fixes, 4 Security Improvements, 5 Translation Improvements, 1 Performance Improvement, 2 Community Improvements, 2 Dependencies, 0 New Contributors * @cstorus made their first contribution in https://github.com/wintercms/winter/pull/616 * @simonmannsfeld made their first contribution in https://github.com/wintercms/winter/pull/623 * @quangtrongonline made their first contribution in https://github.com/wintercms/winter/pull/636 * @nathanlesage made their first contribution in https://github.com/wintercms/winter/pull/665 * @vllvll made their first contribution in https://github.com/wintercms/winter/pull/669 * @robertalexa made their first contribution in https://github.com/wintercms/winter/pull/668 * @iamyigitkoc made their first contribution in https://github.com/wintercms/winter/pull/624 * @hecc127 made their first contribution in https://github.com/wintercms/winter/pull/682 * @prsuhas made their first contribution in https://github.com/wintercms/winter/pull/723

View details View all releases