Twig
The base modules adds custom functionality to Twig
partial() function
The custom partial()
Twig function as a shorthand for:
{% include 'path/to/file' ignore missing with {
key: 'value',
} only %}
With this module enabled, to prevent leaky templates you should do:
{{ partial('path/to/file', {
key: 'value',
}) }}
gtm() function
This function is useful for generating data-track-gtm
attributes and automatically getting the imploding and character escaping. You can pass string parameters or an array of strings
<div data-track-gtm="{{ gtm('One', 'Two', 'Three') }}">
</div>
<div data-track-gtm="{{ gtm(['One', 'Two', 'Three']) }}">
</div>
Would result in:
<div data-track-gtm="One|Two|Three">
</div>
<div data-track-gtm="One|Two|Three">
</div>
Components exposed to Twig craft.viget
sub-object
craft.viget.util.*
fillInEntries($entries, $params, $limit, $additionalIdsToSkip)
This method queries for additional, deduped entries to a fill a number of needed entries
Parameters:
Name | Type | Default |
---|---|---|
entries | array | [] |
params | array | [] |
limit | int | 0 |
additionalIdsToSkip | array | [] |
Returns: array
Example:
{% set featuredArticles = craft.viget.util.fillInEntries(
entry.featuredArticles,
{
section: 'article',
},
4
) %}