Thanks for the kind words.
I can think of a couple of ways to handle this. One is to write a resolver that runs at the end of the install that gets the actual IDs and does a search-and-replace operation on the links. You could make that simpler by using tags with the alias instead of an ID (assuming that you set the resource aliases when creating them):
If you put the aliases and IDs in two arrays, you can use those arrays as arguments to str_replace(). Or you can use a single array of aliases and IDs and do this:
[Update] I realized that there's some danger if one alias is part of another alias, so I've modified the code to include the tags to avoid that.[/Update]
$docs = array (
'[[~alias1]]',
'[[~alias2']],
);
$array_from_to = array();
foreach($docs as $doc) {
$res = $modx->getObject('modResource', array('alias' => $doc));
$array_from_to['[[~' . $doc . ']]'] = $res->get('id');
}
/* Now you have an array like this:
array(
'[[~alias1]]' => 22,
'[[~alias2]]' => 34,
);
*/
/* Do the search and replace */
foreach ($array_from_to as $key => $value) {
$obj = $modx->getObject('modResource', (int) $value);
$text = $obj->getContent();
$text = str_replace(array_keys($array_from_to), $array_from_to, $text);
$obj->setContent($text);
$obj->save();
}
Another thing I've done is to use a resolver to create and set some System Settings for the page IDs (where the 'key' is the alias and the 'value' is the Resource ID). Then you can use links like this:
The down side of this second method is that it breaks if someone changes the alias unless you also change the System Setting. The first method is less confusing to people reading the source and easier to make changes to.
[ed. note: BobRay last edited this post 10 years, 8 months ago.]