Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-13T19:11:27.413Z
Answers.Text: Thanks Mats, didn't know about that. Still a noob at twig.
Answers.UserDisplayName: CreateSean
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-13T18:50:15.120Z
Answers.LastActivityDate: 2016-11-13T18:50:15.120Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <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>
  
Tags: <templating><variable><include>
Title: Use variable passed via include to set value of paramenter
ThreadText: # 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') %}
  
   <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
  
  **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 username_1, didn't know about that. Still a noob at twig.  
  
  ---
  
  