Normally, the [[~123]] syntax for generating a resource’s URL is awesome, but I’m stuck in a situation where I actually need
relative URLs, and I’m wondering if there’s any recommended way to do it.
The situation is that we have a lot of copied folders which use the same structure throughout: each client gets their own folder of pages which is created by duplicating a "master_folder". However, any absolute links become a problem, e.g. a link to master_folder/child/page.html ( [[~123]]) remains unchanged in the copy, whereas it should reflect the corresponding child page in the client folder, e.g. client_folder/child/page.html ([[~456]]). The behavior when you duplicate a resource and its children is to leave the content untouched (so the links remain pointing to [[~123]] back in the master folder when I want them pointing to the child/page.html that is
relative to the client’s folder. Make sense?
One idea is this:
1. Lock down the alias field on the pages so only a super user manager can edit them.
2. Use the UltimateParent snippet to get the id of the parent folder (e.g. client_folder), then us a combination of numerical MODx links and hard-coded aliases in my hrefs, e.g.
<a href="[[~555]]child/page.html">Child Page for this Client</a>
That seems a little low-brow, and changing the aliases of any of the folders involved would break the links... but then again, I’m already breaking the links when I copy the master_folder anyway.
Another idea would be an output filter, e.g.
[[~123:make_url_relative_to=[[!UltimateParent]]]]
Where UltimateParent retrieves the the id of the client folder homepage.
Any other thoughts or perhaps existing solutions?