1

I have two menus. One with countries, one with navigation.

Navigation menu must to have a index link of a active locale. So if I'm at example.com/uk/section and I go to navigation menu and click at index link, I get index of /uk

My countries menu code is:

{% set locales = ['en', 'en_gb', 'sk'] %}
    {# Check if locale equals the requested page locale #}
    {% if locale == craft.locale %}
        {% set current = true %}
    {% else %}
        {% set current = false %}
    {% endif %}
    {% set locale = craft.i18n.getCurrentLocale() %}
      {% for locale in locales %}
         <li>
           <a href="{{ craft.config.siteUrl[locale] ~ craft.request.getPath() }}" class="{{ current ? 'uk-active'}}">{{ craft.i18n.getLocaleById(locale).name }}</a></li>     

When I try to copy

<a href="{{ craft.config.siteUrl[locale] ~ craft.request.getPath() }}" 
class="{{ current ? 'uk-active'}}">{{ craft.i18n.getLocaleById(locale).name }}</a>

and put it to my navigation menu I get

Internal Server Error    array_key_exists(): The first argument should be either a string or an integer

Is it fixable or any other way around?

Dominik Krulak
  • 1,562
  • 14
  • 27

2 Answers2

3

I probably don't fully understand what you're trying to acchieve, but to get to the index page of your current locale, you'd simply use siteUrl().

carlcs
  • 36,220
  • 5
  • 62
  • 139
2

When calling this:

 {% set locale = craft.i18n.getCurrentLocale() %}

locale is set to a full blown LocaleModel object.

What you're probably looking for is its getId() method.

craft.config.siteUrl[locale->getId()]
Brad Bell
  • 67,440
  • 6
  • 73
  • 143