As requested by someone on the #modx IRC channel, here is a short, sweet plugin for placing links in your content using the [~~] tag format by alias.
Example usage:
[~[+alias:
actual-doc-alias-here+]~]
This will return the relative link to the document using the proper alias (if friendly_alias_urls is enabled), prefix, suffix, and alias path (if friendly_alias_paths is enabled). Please note, you must have friendly_urls enabled to use this, and you must make sure that every alias exists that you create a link to, otherwise, the parser in 0.9.1 will return an error like this:
Fatal error: Cannot use [] for reading in C:\dev\xampp\htdocs\modx\manager\includes\document.parser.class.inc.php(807) : regexp code on line 1
Here is the plugin code:
//AliasLinks plugin
$e = &$modx->event;
switch ($e->name) {
case "OnWebPageInit":
if ($modx->config['friendly_urls'] == 1) {
if (is_array($modx->documentListing)) {
foreach ($modx->documentListing as $linkAlias=> $linkDocId) {
$modx->setPlaceholder("alias:{$linkAlias}", "{$linkDocId}");
}
}
}
break;
default :
return; // stop here - this is very important.
}
You’ll need to enable the plugin for the OnWebPageInit event. Let me know if you have any questions.