strapi-plugin-sitemap
strapi-plugin-sitemap copied to clipboard
Pattern: relations array
Feature request
Summary
As of #75 you can add relation fields to the URL pattern like so:
/test/[relation.field]/[id]
Though this only works for single relations. If the relation
would be of target *ToMany
we wouldn't know which entity to query exactly.
Suggested solution(s)
We should allow the pattern to be written like this to select a specific item of an array of relations.
/test/[relation[1].field]/[id]
Here we would select the second entity on the relations array.
So I did come up with a more optimal way to solve this. This method should also open the door for greater customization and resolution of other niche cases:
We could add a way where a custom "resolver" could be injected from the plugins config. I haven't implemented it yet, but it is a promising solution IMO. That way, user's can override the default resolution. We'd just pass in the relevant record and the user would be responsible for changing that into a path.
We'd likely have to disable editing the content type in the admin if a custom resolver is being used, but other than that I believe it's a promising route.
That does sound promising !
Just so we're on the same page. You mean you would write some plugin config to register for example my-key
. Which can be any value you assign to it.
So that we can then create a pattern like: /test/[id]/[my-key]
.
Did I get that right?
I'm trying to generate a new URL bundle as/post/[cities[0].slug]/[slug]
, but it isn't working.
I have a relationship ManyToMany between posts and cities.
Could you help me?
Hi @candidosales.
Thank you for your interest in this feature.
Sadly *ToMany relations are not yet supported in URL patterns. A couple of possible solutions have been suggested here by myself and kibblerz, though none have been implemented as of yet. I'm afraid you'll have to be patient until I find time to work on this feature, or take a stab at it yourself.
Hi @boazpoolman ,
I'm working on it: https://github.com/boazpoolman/strapi-plugin-sitemap/pull/139