Hi guys, I used nested docs plugin with my
pages
collection, it's working fine, but now I wanna use it with other collections to be able to customize and translate all part of my website url.
I try to implement the same logic on my
articles
collection, but If I select a parent from another collection than
articles
, it doesn't works. The
docs param
of my
generateURL
function is not filled by
pages document relation
.
My goal is to be able to target
pages
parent from
articles
collection.
Here is my plugin config:
I guess it will not be possible with this plugin. As I understand it, it only works within the realms of one collection.
But could you probably use your own relation field for this?
So using nested docs for the "internal" hierarachy and a relation to link between collections
Hi, I can target a
pages
parent from
articles
already with the plugin, using a special function. But the data of this parent page is not retrieved and pushed to the
docs
array.
But just to be sure to understand you right: You want e.g. an article to be the child of a page?
Frontend URL like this? /page-slug/article-slug/ ?
exactly, and for others collections later
so like "categories" behave in wordpress and co?
I think so, I never used WP. π
but you also want stuff like this:
/page1-slug/page2-slug/article-slug/
/page1-slug/article1-slug/article2-slug
?
Because if not and you only got one level you probably dont need the nested docs plugin at all. Then it would be kinda easy with simple direct realtions?!
actually, in my Next.js, I'm blocked with static
collections
. With this plugins, I could create only one dynamic route to catch all routes, and be able to translate all url
fr: /produits/livres-32
en: /products/book-32
I handle this with a relation to a "category" collection
the category collection hast a name and slug, which is both localized. With this info I create the localized URLS
yep it would be great, to have this granular control
You could also add the nested docs plugins to each collection, pages, articles and categories (which than determains the base)
So all of them can be nested and you get the info from the breadcrumb field. On top of this you can interconnect the items with a relation field
With this you could create any kind of depth.
Yep, that I want to do π
But it not seems working with the plugin actually :/
Yeah, you need a seperate relation field for this
for the interconnection
For me it makes total sense, that the nested docs plugin only works within a given collection.
But perhaps @jacobsfletch has some more ideas here π
If create my own relation field for
articles
and target
pages collection
. I need to retrieve manually the
parent
field of this page.
If the plugin can push all kind of collections, I don't need to do this kind of stuff, and avoid having two types of logic for the same objective π
I see another guy has the same needs:
https://github.com/payloadcms/plugin-nested-docs/discussions/22Yeah, and as expected, the plugin is not designed for this usecase.
But shouldnt it be kinda simple with the relationship? At least for the "base folder" logic. I guess the url would be constructed something like this, which would be easy to determine in the frontend and run the corresponding checks.
/{doc.relationToPage.slug}/{doc.breadcrumbs[-1].url}
with that you could build:
/page-name/article-structure/with-more-depth/
totally localized
and you dont need to manually retrieve the parent field. It will be directly provided via your API call to the article which has the relation
The API response should look like this:
{
"id": "64c293e2ed24462353dcbe33",
"title": "Article Title",
"slug": "article-title",
"pageRelation": { // your own relation
"id": "649fc774ddd5fbb016a46d1a",
"name": "This is the page",
"slug": "this-is-the-page"
... // all other fields of the relation
},
"breadcrumbs": [
{
"doc": "649fcdaafe5ff392e018a09e",
"url": "/article-parent",
"id": "64e2f477cf4f22007632f866"
},
{
"doc": "649fcde3fe5ff392e018a0e4",
"url": "/article-parent/article-title",
"id": "64e2f477cf4f22007632f867"
}
],
"parent": {...} // from Nested Docs, probably no need to use this data
... // all your other article fields
}
The thing is, I don't want to have several logics to determine the url of my pages in my front-end, the plugin already does the job very well in this respect, I just need to use the breadcrumbs generated to determine my url, independently of my collection.
I've just added these few lines to the plugin, it's not perfect but it seems to work.
Instead of passing the collection in which the function is called, I first check whether the collection passed as a parameter to "createParentField" is divergent.
In my
articles
collection, I create the parentField and target the
pages
collection
I can now generate custom url, without depth or collection limit:
/home (
page
)/blogs(
pages
)/buisness-blogs(
pages
)/article3(
articles
)
I was just about to pop in a link to this discussion, thereβs some others asking about the same functionality
I'm about to finnish this part, I can make a PR if you want π
to be able to give a array of relation collections, and select any document as parent
I have not thought through the full technical aspects of this yet but yea if youβd like to give it a shot, by all means π I would also expect this might be a breaking change
For the moment not really, but I don't know all the payload and plugin mechanics. For now I can pass a specific collection or a array of collections within
createParentField
. And the breadcrumbs is well created. I think i'll add a
collection
field, within breadcrumbs array.
You'll have to make up your own mind π , personally I think this plugin could be so much more powerful with this use.
@jacobsfletch I just pushed a PR. Bear with me, this is the first time I've helped a project π π
https://github.com/payloadcms/plugin-nested-docs/pull/27
@<Clement/> amazing! I donβt have the bandwidth to review that immediately but Iβll keep it tracked
No worries, I'm a bit dubious about the
resaveChildren
hook. I haven't been able to test much yet, but it gives an initial idea of what's possible.
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.