include
Summary
Includes a file.
Usage
{include uri='path_to_file' [ name='namespace' ] [ parameter(s)='value(s)' ]}Parameters
| Name | Type | Description | Required |
|---|---|---|---|
| uri | string | Path + name of the file that should be included. | Yes. |
| name | string | Alternative namespace for the included template. | No. |
| other parameters | any | Parameters that will be passed to the included template. | No. |
Description
This function includes a file in the template from where the function was called. The "uri" parameter must be used to specify the target file. In most cases, the value of this parameter starts with a "design:", which tells the system to look for the desired template within the current (and fallback) design resources. The "name" parameter can be used to specify an alternative namespace for the included template, this is useful for avoiding variable name clashes when including other templates. All other parameters will be passed to the included template as template variables. This function makes it possible to share template code among different parts of the solution.
Examples
Example 1
{include uri='design:example/menu.tpl' something='Hello world'}This example demonstrates how to include a template called "menu.tpl" (which is located within the "example" subdirectory of the "templates" directory. If Exponential is unable to find the template in the current design, it will automatically attempt to locate it in one of the fallback designs or the standard design. The value of the "something" parameter will be available through a variable called $something within the template that is included.
Contributors
- Balazs Halasy Updated
- James Robertson Commenter
- James Ward Commenter
- Bertrand Dunogier Commenter
- Kristof Coomans Commenter
- P. Renaud Commenter
Comments (5 historical)
Written by readers of the earlier documentation sites, kept as they were.
What schemas does the URI attribute support
James Robertson ·
'In most cases, the value of this parameter starts with a "design:"...'
What are the 'other' cases? Does this function support other URI schemas such as 'http:'?
Include limits
James Ward ·
What are the limits on includes? Can I include within an included file? Can I include within an override? Can I include the same file within itself?
Re: Include limits
Bertrand Dunogier ·
- Can I include within an included file?
Yes
- Can I include within an override?
Yes
- Can I include the same file within itself?
Yes
Re: Re: Include limits
Kristof Coomans ·
You have to watch out when including the same file within itself (recursive) if you are defining (def, let) variables in it, this can cause endless loops (the def and let statements will fail because the variable already exists) and you'll have to wait a long time for your page to load (until you reach the maximum template nesting level).
A solution to this is using a unique name parameter to define a new sub-namespace.
Can I use include with...
P. Renaud ·
You cannot guess this by reading the doc, so I tried,and :
- an array as parameter value ? Yes !
{def $my_param=array(10, 20, 30)} {include uri='design:display_array.tpl' param=$my_param}- a hash array as parameter ? Yes !
{def $my_param=hash('abc', 'ABC', 'de', 'DE', 'fghi', 'FGHI')} {include uri='design:miscellaneous/display_array.tpl' param=$my_param}- a node ? Yes !
{def $my_param=$node} {include uri='design:miscellaneous/display_array.tpl' param=$my_param}