Skip to content Skip to footer navigation

Include-if-exists Tag

Renders a view if it exists.

Overview#

You can use this tag to output a view if it exists. If the view doesn't exist, nothing is output instead of throwing a "view not found" exception. Useful if you have some sort of dynamic loop.

{{ include:if_exists src="myview" }}
<s:include:if_exists src="myview" />

This tag accepts everything the include tag does, including slots and the same scope rules.

This tag goes hand in hand with the include tag.
You may be interested in the include:exists tag if you need to do a more complicated conditional check in your template.

Parameters

src

string
required

The name of the view to render. Example: src="cards/author_bio" or :src="var_name".

when

string

Render the view only if a condition is met.

unless

string

The converse of when.

cascade

boolean

When true, the Cascade is made available inside the view. Defaults to false.

params

array

An associative array whose entries become variables in the view. Any parameter you set directly on the tag overrides a matching key.

handle_prefix

string|array

A prefix, or array of prefixes, to strip from the keys in params. With handle_prefix="hero_", a hero_title entry is also available as {{ title }}.

*

mixed

Any other parameter you create will be passed through to the view as a variable.