I'm facing an issue that the frontend doesn't really know the URL of listing elements if I use multiple languages with different "slug" fields.
Example URL structure
/en/round-trips/best-of-oman
/de/rundreisen/...
/fr/...
I also have a collection for the pages that could contain nested documents, but for detail pages (such as a roundtrip) I did not create a sub-page because it feels like double work
1. Create a page
2. Create the roundtrip
3. Go to the page and set the roundtrip as content
The problem occurs if I set links within PayloadCMS (e.g. via the richText field). The link doesn't know the parent URL.
Does anyone have an advise how I could solve it? For now, I'm maintaining a map that knows collection-to-url by language. But I run into some mistakes and I'm looking for a more robust way to solve the issue
I guess a virtual-field that calculates the canonical / or url would help but in order to have that, the collection itself needs know its "parent"
I am trying to follow along here, please bear with me!
Are you saying that your issue is specific to the richText field when linking docs?
I'm not sure how to express this issue, maybe it's not an issue as well but I haven't solved it properly 😅
@jarrod69420 - I still don't know how to solve this issue, may I request your help? 🙂
what kind of front end are you using? I know nextJs's router has support for localization
Yes, but I have different slugs for different languages. Imagine another case, I have a listing collection / table
DE: /autos/cooles-auto (id: 1)
EN: /cars/nice-car (id: 1)
Now I write a blog-post and link to car with id: 1. When rendering I now want to have the absolute path on the page, so
/cars/nice-car
, but the cool car doesn't know that it belongs to /cars/ (?)
For now, I'm maintaining an object that maps locales and the slug / path fields, but it would be nice if the car object itself would know that it belongs to
/cars
hm, yeah I haven't run into that pattern myself. interesting
I could set a parent relationship from the cars collection to the cars page, but it feels repetitive
i mean the map solution you described makes a lot of sense to me. As I reread your issue, that's literally where my head went as well.
Maybe I should maintain that within payload so it could be configured without touching the code..
I'd like to use a single payload instance for 5-6 pages because the content is very similar, but I haven't solved this issue
Maybe @jmikrut has an idea?
well, i think of our nested-docs plugin (which has a parent field, and a "breadcrumbs" field for this explicit purpose)
have you seen that?
how does the car know its parent "page"? those are stored on the parent page, correct?
so when you retrieve the car itself, you don't know the parent
you could have a virtual field that queries parent pages where car is a subpage of the parent page, and then populate the virtual field with the detail that you need
(this is what our plugin does, more or less)
it could either be a virtual field, or a real field that is just kept in sync with beforeChange hooks. that would reduce on the amount of queries you need to make when you retrieve a car
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.