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?

  • Does locale in line 3 have a value? Code looks like there's missing pieces. See this question for a working Language switch solution I use. – carlcs Feb 21 '15 at 17:30
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().

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()]
  • Thanks Brad for your respond and time. To get a index link of a locale was simply to use siteUrl(). – Dominik Krulak Feb 22 '15 at 9:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.