Conditionally hide blocks in PPTX templates

Modern templating engine

Still using Classic syntax? See the Classic documentation.

Learn the differences.

There are two types of blocks for hiding sections. Use the #hide-if and #if logical operations for text and other blocks, and the filter function for the repeatable blocks of information. Here, we will learn how it works, but additionally, review the demo for such case.

Hide table rows

Let us assume we have a collection of employees. We are going to render a table with information about them, but we want to hide employees from a specific department (development).

This is JSON representation of employees data:

{
    "employees": [
        {
            "name": "Derek Clark",
            "department":"marketing"
        },
        {
            "name": "Jessica Adams",
            "department":"sales"
        },
        {
            "name": "Anil Mittal",
            "department":"development"
        }
    ]
}

We will use the template like this:

Hide table row template

The filter function can be placed anywhere on a slide, in any text block. It creates a calculated property:

{{nonDev = employees|filter(@value.department != "development")}}

The token {{nonDev}} does not contain the object of Anil Mittal. He was excluded because working in the development department. After that, the {{nonDev}} token can be used for rendering table rows.

The result table will look like this:

Hide table row result

Hide bullet list items

We will use the same JSON data as in the example for table rows above.

Our template will look like this:

Hide bullet list template

The filter function can be placed anywhere on a slide, in any text block. It creates a calculated property:

{{nonDev = employees|filter(@value.department != "development")}}

The token {{nonDev}} does not contain the object of Anil Mittal. He was excluded because working in the development department. After that, the {{nonDev}} token can be used for rendering list items.

The result list will look like this:

Hide bullet list result

Hide arbitrary text with the “map” function

Let us assume that we would like to present a product to potential customers. If our company has branches in several countries, we may want to display a country-specific company address in the presentation or omit it entirely.

This is JSON representation of company data:

{
    "company": "Tech Solutions",
    "address": "EU"
}

The map function can be used as follows:

{{address|map("None" => "", "EU" => "52 Main Street, Rotterdam, Netherlands", "US" => "81 Avenue Road, Phoenix, AZ")}}

This is the template used for this example:

Hide address with map template

The result for the “US” value will look like this:

Use map to display address result

The result for the “None” value will look like this:

Hide address with map result

Hide arbitrary text with the “#if” operation

Note

Place all conditional operations in the same paragraph as the text you want to show or hide.

Let us assume that we would like to present a product to potential customers. Depending on whether we are delivering the presentation domestically or internationally, we may want to display or hide the company address in the presentation.

This is JSON representation of company data:

{
    "company": "Tech Solutions",
    "showAddress": true
}

The #if operation can be used as follows:

{{#if showAddress}} 81 Avenue Road, Phoenix, AZ

This is the template used for this example:

Hide address with if

The result for a true value will look like this:

Use if to display address result