Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Set a parent of a collection for listing pages

default discord avatar
wiesson2 years ago
9

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"

  • discord user avatar
    jarrod_not_jared
    2 years ago

    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?

  • default discord avatar
    wiesson2 years ago

    I'm not sure how to express this issue, maybe it's not an issue as well but I haven't solved it properly 😅



    @281120856527077378

    - I still don't know how to solve this issue, may I request your help? 🙂

  • default discord avatar
    jakey___2 years ago

    what kind of front end are you using? I know nextJs's router has support for localization

  • default discord avatar
    wiesson2 years ago

    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
  • default discord avatar
    jakey___2 years ago

    hm, yeah I haven't run into that pattern myself. interesting

  • default discord avatar
    wiesson2 years ago

    I could set a parent relationship from the cars collection to the cars page, but it feels repetitive

  • default discord avatar
    jakey___2 years ago

    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.

  • default discord avatar
    wiesson2 years ago

    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

    @364124941832159242

    has an idea?

  • discord user avatar
    jmikrut
    2 years ago

    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 on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.