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?

1
  • 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
    Commented Feb 21, 2015 at 17:30

2 Answers 2

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().

0
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()]
1
  • Thanks Brad for your respond and time. To get a index link of a locale was simply to use siteUrl(). Commented Feb 22, 2015 at 9:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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