{% placeholder %}

October CMS Documentation Docs

{% 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).

___TWIG0___

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

___TWIG0___
    <p>Place this text in the name placeholder</p>
___TWIG1___

# 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:

___TWIG0___
    <p><a href="/contacts">Contact us</a></p>
___TWIG1___

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.

___TWIG0___
    <p><a href="/services">Services</a></p>
    ___TWIG1___
___TWIG2___

# 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:

___TWIG0___
    <!-- Markup for a page with a sidebar -->
    <div class="row">
        <div class="col-md-3">
            ___TWIG1___
        </div>
        <div class="col-md-9">
            ___TWIG2___
        </div>
    </div>
___TWIG3___
    <!-- Markup for a page without a sidebar -->
    ___TWIG4___
___TWIG5___

# Using Placeholders as Variables

Placeholders can be useful for setting inherited variables, such as the active link in page navigation. The {% put %} tag allows you to set values directly. For example, setting the activeNav value to home inside a page template.

___TWIG0___

The variable can be accessed inside the layout template using the placeholder() function. From this, we can determine the active link based on the value set by the page.

___TWIG0___

<ul>
    <li class="___TWIG1___">Home</li>
    <li class="___TWIG2___">Blog</li>
    <li class="___TWIG3___">Contact</li>
</ul>

# Custom Attributes

The placeholder tag accepts two optional attributes &mdash; 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 &mdash; 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:

___TWIG0___

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

___TWIG0___
    There is no ordering information for this product.
___TWIG1___