1

I'm trying to create dynamic urls for a channel or structure section that depend upon the url structure of a different structure (or the first entry in that structure). For example, if the main structure has "foo.com/news/" I want the 'news' channel entries to have urls of "foo.com/news/{slug}".

I came across this question/answer which seems like a great solution: Dynamically setting a channel's Entry URL Format with Craft tags However, like mentioned it's not really dynamic as you need to go back and resave if the parent slug changes. I started doing this and it's turning into a disaster.

Has anyone found a way to do this completely dynamically? Would routing be the right way and how would it be done (I have not used routing)? Or backwards relational entries from the channel to main structure (which seems much less intuitive from CP UI perspective)?

...and if you don't have any ideas, HOW do you deal with urls when you have a 'pages' structure and linking from that to a channel? Based on extensive research, this seems to be the best way of blending structures and channels but my site is too large and complex to hard-code the url structures for the outlying channels/structures.

I don't have the rep to comment on the post above, hence the new question. Thanks much in advance!

****See my comment below gioppe's answer. I have decided against using this dynamic url approach, as explained in my comment.

3
  • I am after the same thing... Almost 3 years :) Did you maybe stumble over the solution?
    – outline4
    Commented Apr 15, 2019 at 22:57
  • No. Read my comment below. I decided that it was a better long-term solution to set the url structures manually so that we would have the option of deviating from our standard setup when needed for SEO and usability.
    – userAW
    Commented Apr 16, 2019 at 13:16
  • OK thanks... I'll have to dig into this myself... This question has been asked many times without a solution that would fit me...
    – outline4
    Commented Apr 16, 2019 at 19:44

1 Answer 1

1

I'm not sure to understand what you're trying to solve but... have you tried using the getElementRoute hook to bypass the default Craft routing and apply any custom processing/routing you need?

3
  • looks interesting. that may work. do you mind providing more detail on where exactly i would use this hook and how i would use it for multiple 'outlying' channels? ie- would i need to hardcode it for each? put them all in one array inside the hook? thanks.
    – userAW
    Commented Feb 28, 2017 at 16:46
  • and this is what i'm trying to do: craftcms.stackexchange.com/questions/9093/… but i need to link the urls the main structure and its outlying structures/channels, preferably in a dynamic manner
    – userAW
    Commented Feb 28, 2017 at 17:17
  • I've changed my mind and decided that urls should not be dynamically set in the site, since I'd prefer to separate system config/data architecture and site output. If we set dynamic urls from the get-go later down the road we will likely regret losing the flexibility of setting urls for each section as whatever is most intuitive/best for SEO, etc. i have not tried your suggestion (nor do i understand it fully) but if anyone else tries it, please comment below to make this question more helpful to others. Thanks for your help.
    – userAW
    Commented Mar 2, 2017 at 17:49

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.