Skip to main content
added 895 characters in body
Source Link

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 %}

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 %}
added 16 characters in body
Source Link

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!

Edit:

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>
        </a>
      </li>
    {% endfor %}
  </ul>
{% endif %}

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!

Edit:

This is part of my current navigation that shows the 2 latest posts related to the current site. One of the URLs it returns 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>
        </a>
      </li>
    {% endfor %}
  </ul>
{% endif %}

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!

Edit:

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>
        </a>
      </li>
    {% endfor %}
  </ul>
{% endif %}
added 915 characters in body
Source Link

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!

Edit:

This is part of my current navigation that shows the 2 latest posts related to the current site. One of the URLs it returns 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>
        </a>
      </li>
    {% endfor %}
  </ul>
{% endif %}

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!

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!

Edit:

This is part of my current navigation that shows the 2 latest posts related to the current site. One of the URLs it returns 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>
        </a>
      </li>
    {% endfor %}
  </ul>
{% endif %}
deleted 1 character in body
Source Link
Loading
Source Link
Loading