Include Function — Dwoo PHP Template Engine

Documentation for the Dwoo include function. Include another template file within a Dwoo template with optional variable passing.

Include allows you to insert other templates into the current template.

include(string $file [, int $cache_time = null [, string $cache_id = null [, string $compile_id = null [, mixed $data = '_root' [, string $assign = null [, array $rest = array() ]]]]]] )
  • file : the resource name to include
  • cache_time : the template cache length in seconds, defaults to null (= will take the Dwoo object cache length)
  • cache_id : the template cache id
  • compile_id : the template compile id
  • data : this is the data array that will be used as the root data for the included template, by default the current data is sent
  • assign : if set, the included file will be assigned to the given variable and it will not be output
  • rest : any number of values that will override the $data argument




As an example, you may have a common header that you would like to include into all of your pages. This can be accomplished like this :

index.html:

<html>
<head>
<title>Some awesome website</title>
</head>
<body>
 
{include('header.html')}
 
</body>
</html>

header.html:

<h1>Some awesome website</h1>
<div id="menu">
{loop $menuItems}<a href="{$url}">{$title}</a>{/loop}
</div>

Output:

<html>
<head>
<title>Some awesome website</title>
</head>
<body>
 
<h1>Some awesome website</h1>
<div id="menu">
<a href="index.html">Home</a>
<a href="products.html">Products</a>
<a href="contact.html">Contact</a>
</div>
 
</body>
</html>