<p>This was on my first craft site (<a href="http://patisseriejanandries.com" rel="nofollow">http://patisseriejanandries.com</a>) so this is a 'warts and all' example. </p>

<p>Productpages was a structure, news a channel, the other pages were singles. The 'nieuwsindex' single is there because I needed a translatable url for the news page, so that single served as a workaround. (more on that here: <a href="https://plus.google.com/116942350387086245334/posts/TBtR3XwuZGx" rel="nofollow">https://plus.google.com/116942350387086245334/posts/TBtR3XwuZGx</a>)
You're still basically hardcoding the nav, but craft does take care of the multi-language urls, pretty nice if you ask me.</p>

<p>The nav template looked like this (which IMO isn't <em>that</em> bad for a first try :) )</p>

<pre><code>   {# set values for the navigation #}
   {# products = structure #}
   {% set productpages = craft.entries.section('productPages').depth(1).find() %}
   {# singles #}
   {% set contact = craft.entries.section('contact').find() %}
   {% set overjanandries = craft.entries.section('overJanAndries').find() %}
   {% set overview = craft.entries.section('overview').find() %}
   {% set news = craft.entries.section('nieuwsIndex').find() %}


    &lt;div id="menu"&gt;
      &lt;a class="close"&gt; &lt;span class="menu-icon icon-cancel"&gt;&lt;/span&gt;&lt;/a&gt;
      &lt;nav role="navigation"&gt;
      &lt;ul&gt;
        {% for page in overview %}
          &lt;li&gt;{{ page.getLink() }}&lt;/li&gt;  
        {% endfor %}
        {% for page in overjanandries %}
          &lt;li&gt;{{ page.getLink() }}&lt;/li&gt;  
        {% endfor %}
        {% for page in productpages %}
         &lt;li&gt;{{ page.getLink() }}&lt;/li&gt;  
        {% endfor %}
         {% for page in news %}
          &lt;li&gt;{{ page.getLink() }}&lt;/li&gt;  
        {% endfor %}
        {% for page in contact %}
          &lt;li&gt;{{ page.getLink() }}&lt;/li&gt;  
        {% endfor %}
      &lt;/ul&gt;
      &lt;/nav&gt;
    &lt;/div&gt;&lt;!-- menu --&gt;
</code></pre>

<p>Following Christian's suggestions I've amended my code and added a 'current' class.
This is working fine (and probably cuts down on DB calls):</p>

<pre><code>{# set values for the navigation #}
{# products = structure #}
{% set productpages = craft.entries.section('productPages').depth(1).find() %}
{# singles #}
{% set contact = craft.entries.section('contact').first() %}
{% set overjanandries = craft.entries.section('overJanAndries').first() %}
{% set overview = craft.entries.section('overview').first() %}
{% set news = craft.entries.section('nieuwsIndex').first() %}
{% set section = craft.request.getSegment(1) %}


&lt;div id="menu"&gt;
  &lt;a class="close"&gt; &lt;span class="menu-icon icon-cancel"&gt;&lt;/span&gt;&lt;/a&gt;
  &lt;nav role="navigation"&gt;
  &lt;ul&gt;
    &lt;li {% if section == overview.uri %}class="current"{% endif %}&gt;{{ overview.getLink() }}&lt;/li&gt;  
    &lt;li {% if section == overjanandries.uri %}class="current"{% endif %}&gt;{{ overjanandries.getLink() }}&lt;/li&gt;  
    {% for page in productpages %}
     &lt;li {% if section == page.uri %}class="current"{% endif %}&gt;{{ page.getLink() }}&lt;/li&gt;  
    {% endfor %}
    &lt;li {% if section == news.uri %}class="current"{% endif %}&gt;{{ news.getLink() }}&lt;/li&gt;  
    &lt;li {% if section == contact.uri %}class="current"{% endif %}&gt;{{ contact.getLink() }}&lt;/li&gt;  
  &lt;/ul&gt;
  &lt;/nav&gt;
&lt;/div&gt;&lt;!-- menu --&gt;
</code></pre>

CC BY-SA 3.0
2014-07-10T11:41:50.037Z
Not bad at all, Erwin! First thing I'd do to further improve on it is to get rid of those for loops to output links to your singles (use `first()` on the entry query).
carlcs
CC BY-SA 3.0
2014-07-10T12:05:59.713Z
I'm giving this one a go because the way my entries are set up in the back end is close to this, but when I view my nav, I get English title output for both languages (although it does output the correct URL slug for the Czech site).
Tyssen
CC BY-SA 3.0
2014-07-10T12:09:02.303Z
Also, how would you add an 'active/current/here' class to the link?
Tyssen
CC BY-SA 3.0
2014-07-10T13:02:24.190Z
@Tyssen exchange `getLink()` with `getUrl()` and `title()` to better control the html output for your links. Then you can also add CSS classes `class="myDefaultClass{{ craft.request.firstSegment == 'mySectionHandle' ? ' current' }}`
carlcs
CC BY-SA 3.0
2014-07-10T13:07:08.277Z
Oh and I'd definitely think twice about not doing the switch to a "pages" structure. Single content is probably easy to copy over and you can also reuse your fields!
carlcs
CC BY-SA 3.0
2014-07-10T13:11:58.120Z
Using getURL & title will give me more control over the HTML but it's still outputting English titles but translated URLs. :? What am I missing to get that working?
Tyssen
CC BY-SA 3.0
2014-07-10T13:41:50.813Z
@Tyssen `{{ mySectionHandle.title }}` should always output the title in the current locale as set in the sections settings.
carlcs
CC BY-SA 3.0
2014-07-10T21:20:29.183Z
Sorted it out now; had forgotten that I'd needed a separate 'heading' field for my singles as you can't currently have translations for title fields for singles.
Tyssen
CC BY-SA 3.0
2014-07-10T11:10:23.840Z
2014-07-10T13:10:35.467Z
2014-07-10T13:10:35.467Z
erwinheiser
<p>I have one main structure "pages" and got rid of all single sections. I also gave each channel's index page an entry in the structure (good for URL translation). Then I added some entry types to it (you can also <a href="http://buildwithcraft.com/help/entry-type-templates">link templates</a> to them) and created my site navigation like in my example code below.</p>

<p>This allows you to translate the slug of the index pages in the CP and you have access to localized URL (<code>page.getUrl</code>) and page title variables (<code>page.title</code>) in your nav template.</p>

<p>Only one level of hierarchy I need. If you have to go deeper, the <a href="http://buildwithcraft.com/docs/templating/tags#nav"><code>nav</code></a> tag's waiting for you! ;)</p>

<pre><code>{# Get top-level entries in pages structure #}
{% set pages = craft.entries.section('pages').level(1) %}

&lt;nav class="navigation" role="navigation"&gt;
    &lt;ul&gt;

        {# Loop through entries (= pages) and list the links #}
        {% for page in pages %}
            &lt;li class="navigation-item"&gt;
                &lt;a href="{{ page.getUrl }}"&gt;{{ page.title }}&lt;/a&gt;
            &lt;/li&gt;
        {% endfor %}

        {# Include links to switch locales #}
        &lt;li class="navigation-item"&gt;
            {% include '_includes/language_switch.html' %}
        &lt;/li&gt;

    &lt;/ul&gt;
&lt;/nav&gt;
</code></pre>

CC BY-SA 3.0
2014-07-10T11:12:22.010Z
pretty solid approach, nice one.
erwinheiser
CC BY-SA 3.0
2014-07-10T03:29:01.650Z
2014-07-10T10:48:23.880Z
2014-07-10T10:48:23.880Z
carlcs
<p>Does anyone have any examples of how they've put together the main site navigation for a multi-lingual site set-up made up of singles, channels and structure?</p>

<p>At the moment I've just hard-coded the nav and done and if else on the locale ID but would like to know if there's a more flexible, future-proof method.</p>

<navigation><localization>
Multi-lingual site navigation made of singles, channels and structure
# Multi-lingual site navigation made of singles, channels and structure

(Asked by: username_0 on 2014-07-10)

Does anyone have any examples of how they've put together the main site navigation for a multi-lingual site set-up made up of singles, channels and structure?

At the moment I've just hard-coded the nav and done and if else on the locale ID but would like to know if there's a more flexible, future-proof method.

**Tags:** navigation, localization

---

## 2 answers

### Answer by username_1 on 2014-07-10. Score: 3 | Accepted answer

This was on my first craft site (http://patisseriejanandries.com) so this is a 'warts and all' example. 
Productpages was a structure, news a channel, the other pages were singles. The 'nieuwsindex' single is there because I needed a translatable url for the news page, so that single served as a workaround. (more on that here: https://plus.google.com/116942350387086245334/posts/TBtR3XwuZGx)
You're still basically hardcoding the nav, but craft does take care of the multi-language urls, pretty nice if you ask me.
The nav template looked like this (which IMO isn't that bad for a first try :) )
   {# set values for the navigation #}
   {# products = structure #}
   {% set productpages = craft.entries.section('productPages').depth(1).find() %}
   {# singles #}
   {% set contact = craft.entries.section('contact').find() %}
   {% set overjanandries = craft.entries.section('overJanAndries').find() %}
   {% set overview = craft.entries.section('overview').find() %}
   {% set news = craft.entries.section('nieuwsIndex').find() %}


    
       
      
      
        {% for page in overview %}
          {{ page.getLink() }}  
        {% endfor %}
        {% for page in overjanandries %}
          {{ page.getLink() }}  
        {% endfor %}
        {% for page in productpages %}
         {{ page.getLink() }}  
        {% endfor %}
         {% for page in news %}
          {{ page.getLink() }}  
        {% endfor %}
        {% for page in contact %}
          {{ page.getLink() }}  
        {% endfor %}
      
      
    

Following Christian's suggestions I've amended my code and added a 'current' class.
This is working fine (and probably cuts down on DB calls):
{# set values for the navigation #}
{# products = structure #}
{% set productpages = craft.entries.section('productPages').depth(1).find() %}
{# singles #}
{% set contact = craft.entries.section('contact').first() %}
{% set overjanandries = craft.entries.section('overJanAndries').first() %}
{% set overview = craft.entries.section('overview').first() %}
{% set news = craft.entries.section('nieuwsIndex').first() %}
{% set section = craft.request.getSegment(1) %}



   
  
  
    {{ overview.getLink() }}  
    {{ overjanandries.getLink() }}  
    {% for page in productpages %}
     {{ page.getLink() }}  
    {% endfor %}
    {{ news.getLink() }}  
    {{ contact.getLink() }}

> **Comments:**
> **username_2**: Not bad at all, Erwin! First thing I'd do to further improve on it is to get rid of those for loops to output links to your singles (use `first()` on the entry query).  
> **username_0**: I'm giving this one a go because the way my entries are set up in the back end is close to this, but when I view my nav, I get English title output for both languages (although it does output the correct URL slug for the Czech site).  
> **username_0**: Also, how would you add an 'active/current/here' class to the link?  
> **username_2**: @Tyssen exchange `getLink()` with `getUrl()` and `title()` to better control the html output for your links. Then you can also add CSS classes `class="myDefaultClass{{ craft.request.firstSegment == 'mySectionHandle' ? ' current' }}`  
> **username_2**: Oh and I'd definitely think twice about not doing the switch to a "pages" structure. Single content is probably easy to copy over and you can also reuse your fields!  
> **username_0**: Using getURL & title will give me more control over the HTML but it's still outputting English titles but translated URLs. :? What am I missing to get that working?  
> **username_2**: @Tyssen `{{ mySectionHandle.title }}` should always output the title in the current locale as set in the sections settings.  
> **username_0**: Sorted it out now; had forgotten that I'd needed a separate 'heading' field for my singles as you can't currently have translations for title fields for singles.  

---

### Answer by username_2 on 2014-07-10. Score: 9

I have one main structure "pages" and got rid of all single sections. I also gave each channel's index page an entry in the structure (good for URL translation). Then I added some entry types to it (you can also link templates to them) and created my site navigation like in my example code below.
This allows you to translate the slug of the index pages in the CP and you have access to localized URL (page.getUrl) and page title variables (page.title) in your nav template.
Only one level of hierarchy I need. If you have to go deeper, the nav tag's waiting for you! ;)
{# Get top-level entries in pages structure #}
{% set pages = craft.entries.section('pages').level(1) %}


    

        {# Loop through entries (= pages) and list the links #}
        {% for page in pages %}
            
                {{ page.title }}
            
        {% endfor %}

        {# Include links to switch locales #}
        
            {% include '_includes/language_switch.html' %}

> **Comments:**
> **username_1**: pretty solid approach, nice one.  

---

