Platform
Templates
Partials
Overview

Partials

Learn how to create reusable pieces of content using partials.

Partials are reusable pieces of content you can use across any of your channel templates. HTML partials can be enabled as "blocks" for use in Knock's drag-and-drop email editor.

In this page, we'll walk through how to create partials and use them in your templates using Knock's code editor or visual editor.

Managing partials

#

Creating and editing partial properties

#

To get started, navigate to Content > Partials in the main sidebar where you can create a new partial.

When creating or editing partials, you can use the following properties:

PropertyDescription
NameA name for your partial.
KeyA unique key for your partial. Cannot be edited after creation.
TypeThe type of content you want to create. One of HTML, markdown, plaintext, or JSON. Cannot be edited after creation.
DescriptionAn optional description of your partial.
Is blockWhether or not to enable this partial as a block within the visual editor (HTML partials only).
Icon nameAn icon to display for this partial within the visual editor.

Partials are environment-specific and follow the same version control model as the rest of Knock.

Creating partial content

#

After creating a partial, you can edit its content in the code editor.

You can include Liquid variables in your content which will be scoped to your partial. When using the partial in a template, you can pass in values for these variables. To include a variable in your partial, use the following syntax: {{ variable_name }}.

Updating existing partial content

#

To update the content of an existing partial, you can return to the partial's code editor.

When you commit or promote your changes, they will be immediately applied to all templates that use the partial in that environment. If you add or remove variables from your partial, you'll want to be sure to update the input values for those variables in any layouts or message templates that use your partial before promoting your changes to higher environments.

Archiving partials

#

Partials can be archived from the "Partials" page or from a specific partial's details page.

Using partials in templates

#

Partials can be used in templates with the code editor or visual editor.

You can also include partials in other partials. Knock will render partials recursively up to a maximum depth of 5.

In the code editor

#

Use partials by using the render tag with the following syntax: {% render 'partial_key' %}. You can also use the partial button in the toolbar to insert a partial.

Pass variables into your partial using the following syntax: {% render 'partial_key', variable_name: 'value' %}. You can pass in plaintext values or Liquid expressions like {% render 'partial_key', variable_name: data.variable_name %}.

The Knock render tag does not support the for and with modifiers.

To replicate the for modifier, use the Liquid for block.

To replicate the with modifier, use the {% assign %} tag to re-assign a variable.

In the visual editor

#

HTML partials can be used in the visual editor if they are enabled as blocks. Add a partial to your template by dragging it from the "Custom blocks" section of the sidebar into the template.

Click a custom block to open the inspect panel to edit variable values. You can enter a plaintext value or a Liquid expression like {{ data.variable_name }}.

Frequently asked questions

#

To use a partial in the visual editor, it must be an HTML partial and enabled as a block.

Partials must be committed before they can be used by templates in a given environment. Templates will always use the published version of a partial.

If you're using a partial that is not yet committed while editing a template, you will not see your latest changes.

Because partial variable inputs are plaintext values, you can't directly pass a JSON object or array of items to a partial variable and then iterate over them within the partial's content.

Instead, you can use Knock's json Liquid helper to transform your input data into a JSON string, and then use the from_json helper to transform the JSON string back into a Liquid object that you can reference within your partial.

For example, if you want a partial to render a list of items, you can pass your list to the partial input like this:

Then, in the partial you can provide the logic to convert the JSON string into a Liquid object and iterate over the items:

You can follow a similar pattern for working with your full data payload or other object variables that are available in the workflow run scope.

Yes! However, because variable inputs for partials are plaintext values, boolean inputs will be interpreted as strings when passed directly into a partial. This means that an input value of the boolean false will be treated as the string "false" in your partial's content, which evaluates as truthy in Liquid.

To ensure that your boolean evaluates properly in your partial, you can use the from_json Liquid helper to transform the input string back into a boolean value:

Alternatively, you can use a Liquid expression to check the string value of the boolean input:

Because empty strings are also truthy in Liquid, if you'd like to check whether or not a value was provided to a partial at runtime you can use the blank object:

Not directly. Liquid variables in your partials are scoped to the partial itself, and serve as placeholders for values that you'll configure within your message templates that use the partial.

To reference variables like recipient, current_message, or workflow within a partial, you can use a placeholder variable in your partial and configure the input value in the template editor to reference these values.


See the FAQ above on how to reference structured data (like a full recipient object) in a partial.

New chat