{% partial %}

{% partial %}

Twig Tag

The {% partial %} tag will parse a CMS partial and render the partial contents on the page. To display a partial called footer.htm, simply pass the name after the partial tag quoted as a string.

___TWIG0___

A partial inside a subdirectory can be rendered in the same way.

___TWIG0___

The Themes documentation has more details on subdirectory usage.

The partial name can also be a variable:

___TWIG0___
___TWIG1___

# Variables

You can pass variables to partials by specifying them after the partial name:

___TWIG0___

You can also assign new variables for use in the partial:

___TWIG0___

Inside the partial, variables can be accessed like any other markup variable:

<p>Country: ___TWIG0___, city: ___TWIG1___.</p>

# Passing Markup as a Variable

It is possible to pass markup to a partial using the body attribute.

___TWIG0___
    This is the card contents
___TWIG1___

The contents are then available as the body variable.

___TWIG0___

# Composable Partials

Composable partials are possible when combined with the {% placeholder %} Twig tag. The following partial defines a header and a body section where HTML content can be added.

<div class="header">
    ___TWIG0___
</div>
<div class="body">
    ___TWIG1___
</div>

Next, you can include the {% put %} tag inside the body to compose the partial result with two HTML content sections.

___TWIG0___
    ___TWIG1___
        <h2>This is the card header</h2>
    ___TWIG2___
    <p>This is the card contents</p>
___TWIG3___

# Setting Partial Contents to a Twig Variable

In any template you can set the partial contents to a variable with the partial() function. This lets you manipulate the output before display. Remember to use the |raw filter to prevent output escaping.

___TWIG0___

___TWIG1___

You may also pass variables to the partial as the second argument.

___TWIG0___

# Checking a Partial Exists

The hasPartial() function can be used to check if a partial exists without rendering the contents, it will return true or false if the partial is found.

___TWIG0___
    ___TWIG1___
___TWIG2___
    <p>Card not found!</p>
___TWIG3___