1

My solution works, but I seem to have some caching issues ... so I'm unsure weather my solution is useful or not?

Entry URI Format of Section (Channel): {{craft.entries.id(530).one().uri}}/{slug}

  • Spezialgebiete => entries.id = 530
  • The correct URI shout be: https://[domain]/tieraerzte/spezialgebiete/[slug of section entry]

The issue / problem is, if entry 'Tierärzte' gets a new slug.
The link to a section item does not recognize the new slug of the parent page.

Should I look for another solution?

Twig Template

{% set spezialgebiete = craft.entries().section('spezialgebiet') %}

<ul>
  {% for item in spezialgebiete %}
    <li>
        {% dump(item.url) %}
        {% include '_ui/objects/link/link' with {
          link: {
              url: item.url,
          },
          text: item.title,
        } only %}
    </li>
  {% endfor %}
</ul>

Screenshot of Section

Screenshot

Screenshot of Sitemap (sorry for German language)

Sitemap

1 Answer 1

2

You don't want to hardcode an ID (530) in a URI template. This is likely to break if you deploy the site to the production environment, because content and their IDs aren't shared between environments.

Instead, I would look for a way to uniquely identify the Spezialgebiete page. For example, by converting it to a single section, or by adding a relation field to relate the entries in your channel to it.

The issue / problem is, if entry 'Tierärzte' gets a new slug.
The link to a section item does not recognize the new slug of the parent page.

Entry URIs are only updated when the entry is saved. So when you change the parent URI, you also need to resave all the other entries that use this entry for their URI in order to update their URIs. You could write a hook that triggers after an entry is saved to enforce that this always happens.


From a broader viewpoint: I've mostly stopped making entry URIs depend on the slug of other entries. Cool URIs don't change. I don't want editors to have the ability to invalidate a bunch of page URLs by changing a single slug. This will mess with SEO and saved bookmarks that people may have (this can be addressed by creating redirects, but it's still not ideal).

Instead, I try to define stable URLs. For example, for your areas of expertise (Spezialgebiete), I would just use spezialgebiete/{slug} or maybe tieraerzte/spezialgebiete/{slug} as the URI format, depending on how the site is structured and what other contents they contain.

1
  • 1
    Hmm ... yes, thank you Moritz! Although it is certainly technically possible, it doesn’t make sense to do so. This simplifies my job; I will now only hide the slug field from editors on the corresponding pages.
    – Marc
    Commented Jun 11 at 12:57

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.