I have an include setup for Navigation which works fine if I hard code in the level of the structure I want to use. However I need this to be set differently if the nav appears in the head or the footer.
head:
{% include "_includes/nav"
with {
'listType' : 'list-inline pull-right',
'navLevel' : '2'
}
%}
footer:
{% include "_includes/nav"
with {
'listType' : 'list-unstyled',
'navLevel' : '1'
}
%}
The include looks like this where I want the .level('<=2')
to have the value passed via the include. However when I attempt this .level('<=navLevel')
or similar the entire nav does not render.
{% set navigation %}
{% set pages = craft.entries.section('navigation').level('<=2') %}
<ul class="{{ listType }}">
{% nav page in pages %}
<li>
{# Check for entry type / get related entry #}
{% if page.type == 'internalLink' %}
{% set linkedEntry = page.sitePageLink.limit(1).first() %}
<a href="{{ linkedEntry.url }}" data-url="{{ entry.url }}">{{ page.title }}</a>
{% endif %}
{# Check for entry type / get offsiteLinks #}
{% if page.type == 'offsiteLink' %}
<a href="{{ page.offSiteLink }}" data-url="{{ entry.url }}">{{ page.title }}</a>
{% endif %}
{% ifchildren %}
{# dropdown not set up yet #}
<ul class="dropdown" style="background:pink">
{% children %}
</ul>
{% endifchildren %}
</li>
{% endnav %}
</ul>
{% endset %}
{# replace data-uri with active class #}
{{ navigation|replace({('data-url="' ~ craft.request.getUrl() ~ '"'): 'class="active"'})|raw }}
Please advise