Edit on GitHub

{% placeholder %}

The {% placeholder %} tag will render a placeholder section which is generally used inside Layouts. This tag will return any placeholder contents that have been added using the {% put %} tag, or any default content that is defined (optional).

{% placeholder name %}

Content can then be injected into the placeholder in any subsequent page or partial.

{% put name %}
    <p>Place this text in the name placeholder</p>
{% endput %}

Default placeholder content

Placeholders can have default content that can be either replaced or complemented by a page. If the {% put %} tag for a placeholder with default content is not defined on a page, the default placeholder content is displayed. Example placeholder definition in the layout template:

{% placeholder sidebar default %}
    <p><a href="/contacts">Contact us</a></p>
{% endplaceholder %}

The page can inject more content to the placeholder. The {% default %} tag specifies a place where the default placeholder content should be displayed. If the tag is not used the placeholder content is completely replaced.

{% put sidebar %}
    <p><a href="/services">Services</a></p>
    {% default %}
{% endput %}

Checking a placeholder exists

In a layout template you can check if a placeholder content exists by using the placeholder() function. This lets you to generate different markup depending on whether the page provides a placeholder content. Example:

{% if placeholder('sidemenu') %}
    <!-- Markup for a page with a sidebar -->
    <div class="row">
        <div class="col-md-3">
            {% placeholder sidemenu %}
        <div class="col-md-9">
            {% page %}
{% else %}
    <!-- Markup for a page without a sidebar -->
    {% page %}
{% endif %}

Custom attributes

The placeholder tag accepts two optional attributes — title and type. The title attribute is not used by the CMS itself, but could be used by other plugins. The type attribute manages the placeholder type. There are two types supported at the moment — text and html. The content of text placeholders is escaped before it's displayed. The title and type attributes should be defined after the placeholder name and the default attribute, if it's presented. Example:

{% placeholder ordering title="Ordering information" type="text" %}

Example of a placeholder with a default content, title and type attributes.

{% placeholder ordering default title="Ordering information" type="text" %}
    There is no ordering information for this product.
{% endplaceholder %}

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.2 is now available!

Published June 3, 2023
The Winter CMS maintainers are pleased to announce that Winter CMS v1.2.2 is now available, including child themes support, a new Icon Finder widget, various improvements to the Media Manager and much more.

View this post Read all posts

Latest Winter CMS release


Released May 31, 2023
13 UX/UI Improvements, 22 API Changes, 19 Bug Fixes, 0 Security Improvements -, 6 Translation Improvements, 1 Performance Improvement, 3 Community Improvements, 3 Dependencies, 0 New Contributors * @Teranode made their first contribution in https://github.com/wintercms/winter/pull/806 * @wpjscc made their first contribution in https://github.com/wintercms/winter/pull/841 * @xitara made their first contribution in https://github.com/wintercms/winter/pull/858 * @webbati made their first contribution in https://github.com/wintercms/winter/pull/869 * @zaxbux made their first contribution in https://github.com/wintercms/winter/pull/890 * @djpa3k made their first contribution in https://github.com/wintercms/winter/pull/911

View details View all releases