<p>A section's <code>handle</code> is the machine-readable identifier for a section, it's not localizable and has nothing to do with URLs of entries in that section. Instead of accessing the section in your template, you need <em>the entries in that section</em> to get their localized URLs.</p>
<p>Since you'te talking about breadcrumbs, I'll assume you want a list of links like this:</p>
<pre><code>/articles/
/articles/article-about-something/
</code></pre>
<p>In your example, the current entry would have the URL <code>/articles/article-about-something/</code> and you're trying to get the link to <code>articles</code>. Now the solution depends on what section the <code>articles</code> belongs to. Since your <code>articles</code> section is a channel (so no hierarchies), I assume your <code>/articles/</code> pages is another section, probably a single? In this case, you'll want to use an entry query to get that single entry and access its URL, which will be localized automatically:</p>
<pre class="lang-twig prettyprint-override"><code>{% set articlesListing = craft.entries().section('articlesListing').one() %}
{% if articles_index %}
    {% set articles_url = articlesListing.getUrl() %}
{% endif %}
</code></pre>
<hr />
<p>If the <code>/articles/</code> page is a static route or just matched based on the template name, there's no built-in way to localize it. You'll have to hard-code your local URLs and make sure your routes/template names match all localized slugs.</p>

CC BY-SA 4.0
2022-02-16T15:28:08.953Z
Right you are. /articles/ is of course not part of the section "Articles" at all, but rather it's a single called "articlesListing". So yea, `craft.entries().section('articlesListing').one()` does indeed give me the right thing. I will fix my question to reflect this serious oversight. Thanks.
InanisAtheos
CC BY-SA 4.0
2022-02-16T15:01:50.127Z
2022-02-16T15:33:06.077Z
2022-02-16T15:33:06.077Z
MoritzLost
<p>I'm trying to contruct breadcrumbs for entries under a specific section. This feels like such a &quot;how-hard-could-it-possibly-be&quot; type of question, but I've been at this for a lot more time than I ever expected, so finally asking a question here.<br />
So far, this the relevant parts of what I have:</p>
<pre><code>{% macro breadcrumbs(type, entryId) %} 
    {% if type == 'article' %}
        {% set articleEntry = craft.entries.id(entryId).one() %}
        
        {% set section = craft.app.sections.getSectionByHandle('articles') %}
        {% set sectionUrl = siteUrl ~ section.handle|kebab %}

        {{ dd(sectionUrl, section.name) }}
    {% endif %}
{% endmacro %}
</code></pre>
<p>This (so far) simple macro is called from the article template.<br />
The <code>dd</code> here outputs the following:</p>
<pre><code>^ &quot;//localhost:3000/sv/articles&quot;
^ &quot;Articles&quot;
</code></pre>
<p><code>articles</code> should really be <code>artiklar</code> in both the contructed URL as well as the name.</p>
<p>I have looked at <a href="https://craftcms.stackexchange.com/questions/1682/get-the-current-section-handle">this question</a> which is 7 years old, but it only fetches the sections &quot;main&quot; name, handle and uri.</p>
<p><code>articles</code> is a channel, if that matters.</p>
<p>I realize I'm probably going about this issue in totally the wrong way. Feel free to give me pointers on where I'm going wrong.</p>
<p>Edit: @moritzlost made the issue quite apparent: The page that handles the listing/overview of all articles, isn't actually a part of the <code>articles</code> channel. This is of course obvious. I'll leave the question stand in case others end up in the same brain-warp.</p>
<p>What my code ended up looking like:</p>
<pre><code>{% macro breadcrumbs(type, entryId) %} 
    {% if type == 'article' %}
        {% set articleEntry = craft.entries.id(entryId).one() %}
        
        {% set section = craft.entries().section('articlesListing').one() %}
        {% set sectionUrl = section.getUrl() %}
        {% set sectionName = section.seo.metaGlobalVars.seoTitle %} {# Gets the SEO title instead of the default section name. #}

        {{ dd(sectionUrl, sectionName) }}
    {% endif %}
{% endmacro %}
</code></pre>
<p>Which yields this:</p>
<pre><code>^ &quot;//localhost:3000/sv/artiklar&quot;
^ &quot;Artiklar om djurhållning&quot;
</code></pre>

CC BY-SA 4.0
2022-02-16T14:52:59.477Z
What link(s) are you trying to output? What kind of content (section, entry type) are you serving for that link?
MoritzLost
<templating><localization><sections><multi-site>
Get the localized handle and slug for "current" section for constructing breadcrumbs
# Get the localized handle and slug for "current" section for constructing breadcrumbs

(Asked by: username_0 on 2022-02-16)

I'm trying to contruct breadcrumbs for entries under a specific section. This feels like such a "how-hard-could-it-possibly-be" type of question, but I've been at this for a lot more time than I ever expected, so finally asking a question here.
So far, this the relevant parts of what I have:
{% macro breadcrumbs(type, entryId) %} 
    {% if type == 'article' %}
        {% set articleEntry = craft.entries.id(entryId).one() %}
        
        {% set section = craft.app.sections.getSectionByHandle('articles') %}
        {% set sectionUrl = siteUrl ~ section.handle|kebab %}

        {{ dd(sectionUrl, section.name) }}
    {% endif %}
{% endmacro %}

This (so far) simple macro is called from the article template.
The dd here outputs the following:
^ "//localhost:3000/sv/articles"
^ "Articles"

articles should really be artiklar in both the contructed URL as well as the name.
I have looked at this question which is 7 years old, but it only fetches the sections "main" name, handle and uri.
articles is a channel, if that matters.
I realize I'm probably going about this issue in totally the wrong way. Feel free to give me pointers on where I'm going wrong.
Edit: @moritzlost made the issue quite apparent: The page that handles the listing/overview of all articles, isn't actually a part of the articles channel. This is of course obvious. I'll leave the question stand in case others end up in the same brain-warp.
What my code ended up looking like:
{% macro breadcrumbs(type, entryId) %} 
    {% if type == 'article' %}
        {% set articleEntry = craft.entries.id(entryId).one() %}
        
        {% set section = craft.entries().section('articlesListing').one() %}
        {% set sectionUrl = section.getUrl() %}
        {% set sectionName = section.seo.metaGlobalVars.seoTitle %} {# Gets the SEO title instead of the default section name. #}

        {{ dd(sectionUrl, sectionName) }}
    {% endif %}
{% endmacro %}

Which yields this:
^ "//localhost:3000/sv/artiklar"
^ "Artiklar om djurhållning"

**Tags:** templating, localization, sections, multi-site
> **Comments:**
> **username_1**: What link(s) are you trying to output? What kind of content (section, entry type) are you serving for that link?  

---

## 1 answers

### Answer by username_1 on 2022-02-16. Score: 1 | Accepted answer

A section's handle is the machine-readable identifier for a section, it's not localizable and has nothing to do with URLs of entries in that section. Instead of accessing the section in your template, you need the entries in that section to get their localized URLs.
Since you'te talking about breadcrumbs, I'll assume you want a list of links like this:
/articles/
/articles/article-about-something/

In your example, the current entry would have the URL /articles/article-about-something/ and you're trying to get the link to articles. Now the solution depends on what section the articles belongs to. Since your articles section is a channel (so no hierarchies), I assume your /articles/ pages is another section, probably a single? In this case, you'll want to use an entry query to get that single entry and access its URL, which will be localized automatically:
{% set articlesListing = craft.entries().section('articlesListing').one() %}
{% if articles_index %}
    {% set articles_url = articlesListing.getUrl() %}
{% endif %}


If the /articles/ page is a static route or just matched based on the template name, there's no built-in way to localize it. You'll have to hard-code your local URLs and make sure your routes/template names match all localized slugs.

> **Comments:**
> **username_0**: Right you are. /articles/ is of course not part of the section "Articles" at all, but rather it's a single called "articlesListing". So yea, `craft.entries().section('articlesListing').one()` does indeed give me the right thing. I will fix my question to reflect this serious oversight. Thanks.  

---

