{{ include('snippets/icon-search') }}
{{ include(some_var) }}

By default the include function assumes you want to include .html or .canvas files, this means you dont need to specify a file format.

Included templates have access to the variables of the active context. The context is passed by default to the template but you can also pass additional variables:

{# template.html will have access to the variables from the current context and the additional ones provided #}
{{ include('template.html', {foo: 'bar'}, with_context = false) }}
{# no variables will be accessible #}
{{ include('template.html', with_context = false) }}

When you set the ignore_missing flag, Canvas will return an empty string if the template does not exist:

{{ include('sidebar.html', ignore_missing = true) }}

You can also provide a list of templates that are checked for existence before inclusion. The first template that exists will be rendered:

{{ include(['page_detailed.html', 'page.html']) }}

If ignore_missing is set, it will fall back to rendering nothing if none of the templates exist, otherwise it will throw an exception.

When including a template created by an end user, you should consider sandboxing it:

{{ include('page.html', sandboxed = true) }}


templateThe template to renderString
variablesThe variables to pass to the templateObject
with_contextWhether to pass the current context variables or notBoolean
ignore_missingWhether to ignore missing templates or notBoolean
sandboxedWhether to sandbox the template or notBoolean

Was this helpful?

Copyright © 2024 Blutui.