How do I use the document aliases in links within a ModX document as well as within PHP code in snippets? The wiki has several related articles that all seem to contradict themselves. Also, if I’m writing PHP code and want to, for example, echo out a link, how do I use an alias to return or inject the proper URL???
This one is correct:
http://wiki.modxcms.com/index.php/Placeholders_used_by_MODx_Pages_and_Templates
But to put a dynamic (not static) link use
href="[~[*id*]~]" in template and chunks - html code
The [*id*] is a built in placeholder that the actual document will replace with its right id number.
Another nice one to use is [*parent*]
http://modxcms.com/document-tvs.html
The id will automatically return to alias by mod-rewrite (.htaccess) if you use FURL with alias.
Also remember because you are able to give multiple documents the same alias (so you can do something like "company.com/shop-one/history" and "company.com/shop-two/history" for example) when using AliasLinks, it’ll prob return the first result ("company.com/shop-one/history") even if you’re expecting shop two’s history page to be linked to.
Thanks for the links, everyone. Judging by what Sal posted, I’m guessing that there is no native support for what I want to do (which is what the plugin that he links to does).
As for why I want to use aliases, I would counter with why not? They are far more portable. Perhaps my situation is unique though. I am doing some work for a client - the client already uses ModX, but wanted us to build out a registration and membership area and a bunch of other custom things that all tied into ModX. To do so we pulled down a copy of their site and set up a copy on a development server. 3-months later our work is complete, but in the meantime they added more documents. So new we have several new documents as part of our work that share IDs with their new documents. This prevents me from doing a simple import/export of documents at the database level, and also means that any hard-coded links that I’ve included in our new code will need to be changed to use the new IDs. Essentially I now have to set everything up from scratch on the new server.
I recently came across the documentation on friendly URLs using document aliases. I have those working now where I can enter something like <a href="myalias.html"> and have ModX figure out what to serve. Since these aliases exist, it would be much more handy if instead of writing all our code to use the [~id~] placeholder, I could use an [~alias~] PH instead. Then I wouldn’t have to worry about what the document ID was in the final live site - as long as the aliases stayed the same (and were unique) then I could just insert the new document records in the database and be done with things.
FWIW - I think this functionality should be built in to ModX. As I said, it makes things much more portable between servers, and also make things easier to remember (much easier to remember the alias for a contact page is ’contact’ rather than the ID for it.) Think of it like a the slug value in Wordpress, et. al.
To search and replace all over:
http://modxcms.com/Doc-Finder-Module-1962.html
Maybe these plugins "still" can help you:
http://www.modxcms.com/NGRedirect-1984.html
http://www.modxcms.com/NGInternalLinks-1965.html
//Do try out the AliasLinks plugin, it might work if you’re not using PHx.
mrhaw - Thanks, it does indeed work in my 0.9.6.2 install.
Now, what is the execution code of a plugin? Is it such that i can still use the AliasLink plugin inside a PHP string and it will be translated after the PHP has been executed? Or do I instead need to use part of the API to render a link from a snippet, and if so what function would do this? (or at least return the document ID so I could do something like ’<a href="index.php?id=’.aliasLookupFunc(’myalias’).’">...’)