Simple question really, and the custom alias plugin provides this feature but it has
some other issues with stripping special characters out of URLs thus is not an option : How do I prepend the document’s ID to my URLs ?
There is no built in TVs to add as prefix and of course [~[*id*]~] won’t work...
Maybe a custom TV with an @EVAL ?
CustomAlias is using the following code to retrieve the id and add it to the url :
// Get the ID of the document, if you want to use it in your alias
$id = '.'.$modx->event->params['id'];
(.........)
// Update the database
$rows_affected = $modx->db->update(
$fields,
$table,
"id = {$e->params['id']}"
);
.: COO - Commerce Guys - Community Driven Innovation :.
MODx est l'outil id
-
MODX Staff
- 12,272 Posts
096 doesn’t have those issues with special characters and I suppose that you could take the same logic from the core now and update the custom alias plugin with that.
Ryan Thrash, MODX Co-Founder
Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
It means that there is no practical mean to prepend the url with the ID without using CustomAlias ?
.: COO - Commerce Guys - Community Driven Innovation :.
MODx est l'outil id
-
MODX Staff
- 12,272 Posts
I don’t think so automatically. You could of course always go back to the doc after saving and insert [*id*]- to prepend the alias, but that seems like extra work to me. I’d personally update the custom alias plugin, since it’s only introducing overhead when the document is saved and is otherwise out of the loop.
Ryan Thrash, MODX Co-Founder
Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
Ok thanks for the advice Ryan I’ll try to go ahead with that if it’s decided that we opt for this for the website I’d eventually need that feature...
.: COO - Commerce Guys - Community Driven Innovation :.
MODx est l'outil id
-
MODX Staff
- 12,272 Posts
Out of curiosity, why does the client want the Doc ID in every alias?
Ryan Thrash, MODX Co-Founder
Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
That’s what he has posted
here on the french boards (in french).
He was afraid that if he changed title, the link to the resource would return a 404 page. I already explained to him before he posted that the alias was only updated if the alias field had no value, therefore changing the title would not change the alias. But that does not make sense to him to have an outdated alias : he wants it updated.
His idea (because a friend of his has a website with that feature -> I don’t remember the url) is that the ID should be prepended to the url in such a way that the alias has actually no real value to locate the resource : only the ID is taken into account by the system. For instance in his example 214-il-fait-beau-en-mai.html would return the same document as 214-whatever-alias.html does.
.: COO - Commerce Guys - Community Driven Innovation :.
MODx est l'outil id
-
MODX Staff
- 12,272 Posts
I suppose that’s a valid way to handle things. He will definitely need a custom plugin to address his requirement.
Ryan Thrash, MODX Co-Founder
Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
Especially since this url scheme would mean handling 301 headers correctly since a document could have X aliases for one ID. And correct me if I am wrong but SEO Stricts URLs is not built to handle this kind of url patterns... that would mean building a plugin which would be a tweaked combo of CustomAlias and SEO Stricts URLs... tricky !
Plus, how much would that cost ?
I sure can’t be the one to write the plugin...
.: COO - Commerce Guys - Community Driven Innovation :.
MODx est l'outil id