<ev:include />

Also <ev:partial /> includes another EVML file containing re-usable code within your template. Common usages include rendering the same product layout on categories as recently viewed or related products. 

<!-- shop/index.evml --->
...
<?ev for(var i in products){ ?>
    <ev:include src="shop/product.partial.evml" product="products[i]" />
<?ev } ?>
...

Attributes

<ev:include> does not represent an HTML element and only has one dedicated src attribute. However it also has some unusual attribute capabilities that are of note (see below). 

cache

Reserved, but not yet implemented. Please do not use cache as a variable name.

true (default)
The rendering of the partial will be cached.

false
Do not cache rendering of the partial. This is important where data changes such as cart partial rendering.

src

The path of the file to include within your template. The value of this attribute should conform to our Resources URL Format.

[variable]

variable="value"

The included file inherits all of the properties available to your template, but you may add additional properties for the included file to use (described below). 



Assigning variables and their values

In the following we take the example of iterating through a list of sub-categories within a shop template and utilising a reusable category include file. 

<!-- File: shop/index.evml --->
...
<h2>Sub-categories for {{ category.title }}</h2>

<?ev 
    // loop through sub-categories
    for(var i in category.children){ 
        var childNumber = i;
?>

    <ev:include src="shop/category.include.evml" parent="category" category="category.children[i]" />
<?ev } ?>

{{ category.title }} had {{ childNumber+1 }} sub-categories
...

The attribute category="category.children[1]" creates a new non-conflicting category variable within the included file, which is discarded after execution. Yet the childNumber declared within the for loop will be available both within the included file, but also after execution.

<!-- File: shop/category.include.evml --->
...
{{ childNumber }}
<h1>{{ category.title }}</h1>
<p>{{ category.description }}</p>
...

Strings, booleans and numbers

On rare occasions, and I mean rare, you may need to send a string, boolean or number value to your included file. To do this you need to let Evance know that you're not supplying a variable name by type casting the value.

  • Strings
    Tell Evance your value is a string and you're not trying to reference a variable.
    variable="(string) value"

  • Booleans
    Tell Evance your value is a true or false value and not a variable.
    variable="(bool) true | false"

  • Numbers
    Yes, you guessed, it's a number and not a variable.
    variable="(number) value"


<ev:include src="~/theme/includes/person.evml" name="(string) Bob" customer="(bool) true" age="(number) 21" />

<!-- File: ~/theme/includes/person.evml --->
{{ name }} is {{ age }} years old and is {{ customer ? 'an existing' : 'potential' }} customer.