<p>You'll need to concatenate the string you pass to the <code>level</code> parameter, using the <code>~</code> operator:</p>

<pre><code>{% set pages = craft.entries.section('navigation').level('&lt;='~navLevel) %}
</code></pre>

CC BY-SA 3.0
2016-11-13T19:11:27.413Z
Thanks Mats, didn't know about that. Still a noob at twig.
CreateSean
CC BY-SA 3.0
2016-11-13T18:50:15.120Z
2016-11-13T18:50:15.120Z
Mats Mikkel Rummelhoff
<p>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.</p>

<p>head:</p>

<pre><code>      {% include "_includes/nav"
        with {
          'listType' : 'list-inline pull-right',
          'navLevel'  : '2'
        }
      %}
</code></pre>

<p>footer:</p>

<pre><code>      {% include "_includes/nav"
        with {
          'listType' : 'list-unstyled',
          'navLevel'  : '1'
        }
      %}
</code></pre>

<p>The include looks like this where I want the <code>.level('&lt;=2')</code> to have the value passed via the include. However when I attempt this <code>.level('&lt;=navLevel')</code> or similar the entire nav does not render.</p>

<pre><code>{% set navigation %}

 {% set pages = craft.entries.section('navigation').level('&lt;=2') %}

 &lt;ul class="{{ listType }}"&gt;
   {% nav page in pages %}
     &lt;li&gt;
       {# Check for entry type / get related entry #}
       {% if page.type == 'internalLink' %}
           {% set linkedEntry = page.sitePageLink.limit(1).first() %}
           &lt;a href="{{ linkedEntry.url }}"  data-url="{{ entry.url }}"&gt;{{ page.title }}&lt;/a&gt;
       {% endif %}

       {# Check for entry type / get offsiteLinks #}
       {% if page.type == 'offsiteLink' %}
           &lt;a href="{{ page.offSiteLink }}"  data-url="{{ entry.url }}"&gt;{{ page.title }}&lt;/a&gt;
       {% endif %}

       {% ifchildren %}
         {# dropdown not set up yet #}
          &lt;ul class="dropdown" style="background:pink"&gt;
              {% children %}
          &lt;/ul&gt;
      {% endifchildren %}

     &lt;/li&gt;
   {% endnav %}
 &lt;/ul&gt;

 {% endset %}

 {# replace data-uri with active class #}
 {{ navigation|replace({('data-url="' ~ craft.request.getUrl() ~ '"'): 'class="active"'})|raw }}
</code></pre>

<p>Please advise</p>

<templating><variable><include>
Use variable passed via include to set value of paramenter
# Use variable passed via include to set value of paramenter

(Asked by: username_0 on 2016-11-13)

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') %}

 
   {% nav page in pages %}
     
       {# Check for entry type / get related entry #}
       {% if page.type == 'internalLink' %}
           {% set linkedEntry = page.sitePageLink.limit(1).first() %}
           {{ page.title }}
       {% endif %}

       {# Check for entry type / get offsiteLinks #}
       {% if page.type == 'offsiteLink' %}
           {{ page.title }}
       {% endif %}

       {% ifchildren %}
         {# dropdown not set up yet #}
          
              {% children %}
          
      {% endifchildren %}

     
   {% endnav %}
 

 {% endset %}

 {# replace data-uri with active class #}
 {{ navigation|replace({('data-url="' ~ craft.request.getUrl() ~ '"'): 'class="active"'})|raw }}

Please advise

**Tags:** templating, variable, include


---

## 1 answers

### Answer by username_1 on 2016-11-13. Score: 2 | Accepted answer

You'll need to concatenate the string you pass to the level parameter, using the ~ operator:
{% set pages = craft.entries.section('navigation').level('<='~navLevel) %}

> **Comments:**
> **username_0**: Thanks Mats, didn't know about that. Still a noob at twig.  

---

