I set up 2 sites (locally) running Craft 3.6.7:

  • English (Handle: english, Base URL: '/en/')
  • German (Handle: german, Base URL: '/de/')

I've made a blog section that is enabled for both languages with a 'blog/{slug}' URI for both and they also use the same template '_blog/_entry'.

There is a single blog post which translates on both languages, with slugs 'test-english' (for the english locale)' and test-german' (for the german locale).

Both posts are accessible as expected using '/en/blog/test-english' and '/de/blog/test-german'. The problem is when I try to link to an entry, the URL that's returned is always 'blog/test-english' or 'blog/test-german', without the Base URL, so the german URL never works ('blog/test-german' doesn't exist).

I've been looking everywhere trying to find if this is the expected behavior, but everything points in the direction it's not. Thank you in advance!


This is part of my current navigation that shows the 2 latest posts related to the current site. One of the URLs it returns (without '/en') is: 'blog/get-upselling-inspiration-with-the-deal-library'.

{% set latestPosts = craft.entries().section('blog').siteId(currentSite.id).limit(2) %}

{% if latestPosts.exists() %}
  <ul class="navigation-dropdown__posts">
    {% for post in latestPosts.all() %}
      <li class="navigation-dropdown__post">
        <a class="navigation-dropdown__anchor" href="{{ post.url }}">
          {% if post.singleImage|length %}
            {% for image in post.singleImage.all() %}
              <img class="navigation-dropdown__image" src="{{ image.getUrl('blogThumbnail') }}" alt="{{ image.title }}" />
            {% endfor %}
          {% endif %}
          <strong>{{ post.title }}</strong>
    {% endfor %}
{% endif %}

Edit 2: Solved it for now like this, but I don't think this is how it's supposed to work

{% for siteForEntry in entry.getSupportedSites %}
  {# get the site #}
  {% set site = craft.app.getSites.getSiteById(siteForEntry.siteId) %}
  {# check if it's the current site #}
  {% if site.id == entry.siteId %}
    <option value="{{ site.handle }}" selected>{{ site.name }}</option>
  {% else %}
    {% set entryForOtherSite = craft.entries.id(entry.id).site(site).one() %}
    {# if it's not the current site, get the entry for this site #}
    {% if entryForOtherSite.uri == '__home__' %}
      {% set prettyUrl = site.baseUrl() %}
    {% else %}
      {% set prettyUrl = site.baseUrl() ~ entryForOtherSite.uri %}
    {% endif %}

    <option value="{{ site.handle }}" onclick="location.href='{{ prettyUrl }}';">{{ site.name }}</option>
  {% endif %}
{% endfor %}
  • 1
    Can you show the code you have in your template?
    – Oli
    Commented Feb 24, 2021 at 16:59
  • @Oli I added the navigation template code to the original post, thank you!
    – Gideon
    Commented Feb 25, 2021 at 11:45


Your Answer

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

Browse other questions tagged or ask your own question.