Nunjucks syntax
Depending on your environment you'll want to use render
or include
. As a rule of thumb: server-side use include
, precompiled browser use render
. If you're using vf-eleventy you should use include
.
Using include
You'll need to pass a context object from your code or Yaml file (exampe), as well as the path to the Nunjucks template. Nunjucks' include
is an abstraction of render
and provides some additional portability.
{% set context fromYourYamlFile %}
- or -
{% set context = {
"component-type": "block",
"classModifier": "global",
"navigation": [
{
"text": "services",
"navigation_href": "JavaScript:Void(0);"
},
{
"text": "research",
"navigation_href": "JavaScript:Void(0);"
},
{
"text": "training",
"navigation_href": "JavaScript:Void(0);"
},
{
"text": "about us",
"navigation_href": "JavaScript:Void(0);"
}
]
}
%}
{% include "../path_to/vf-navigation/vf-navigation.njk" %}
Using render
This approach is best for bare-bones Nunjucks environments, such as precompiled templates with the Nunjucks slim runtime where include
is not be available.
{% render '@vf-navigation', {
"component-type": "block",
"classModifier": "global",
"navigation": [
{
"text": "services",
"navigation_href": "JavaScript:Void(0);"
},
{
"text": "research",
"navigation_href": "JavaScript:Void(0);"
},
{
"text": "training",
"navigation_href": "JavaScript:Void(0);"
},
{
"text": "about us",
"navigation_href": "JavaScript:Void(0);"
}
]
} %}
HTML
<nav class="vf-navigation vf-navigation--global">
<ul class="vf-navigation__list | vf-list--inline | vf-cluster__inner">
<li class="vf-navigation__item">
<a href="JavaScript:Void(0);" class="vf-navigation__link">services</a>
</li>
<li class="vf-navigation__item">
<a href="JavaScript:Void(0);" class="vf-navigation__link">research</a>
</li>
<li class="vf-navigation__item">
<a href="JavaScript:Void(0);" class="vf-navigation__link">training</a>
</li>
<li class="vf-navigation__item">
<a href="JavaScript:Void(0);" class="vf-navigation__link">about us</a>
</li>
</ul>
</nav>