Skip to content

Instantly share code, notes, and snippets.

@rtripault
Created November 12, 2010 04:19
Show Gist options
  • Save rtripault/673720 to your computer and use it in GitHub Desktop.
Save rtripault/673720 to your computer and use it in GitHub Desktop.
Link to translated resource (or homepage if no translation available) for MODx Revolution
<?php
// if we are in context www-en…
if ($modx->context->get('key') == "www-en") {
$o = '';
// …grab www-fr infos
$modx->switchContext('www-fr');
$ss = $modx->getOption('site_start');
$ctx = $modx->context->get('key');
// grab datas from TV named multi (containing ID of the translated resource)
$tvv = $modx->resource->getTVValue('multi');
// if there is no translation (empty TV), return the start_start ID
if (empty($tvv)) {
$o = $ss;
} else {
$o = $tvv;
}
$u = $modx->makeUrl($o,$ctx,'','full');
// going back to original context
$modx->switchContext('www-en');
return $u;
}
// else if we are in context www-fr…
else if ($modx->context->get('key') == "www-fr") {
// …grab www-en infos
$modx->switchContext('www-en');
$ss = $modx->getOption('site_start');
$ctx = $modx->context->get('key');
$tvv = $modx->resource->getTVValue('multi');
if (empty($tvv)) {
$o = $ss;
} else {
$o = $tvv;
}
$u = $modx->makeUrl($o,$ctx,'','full');
// going back to original context
$modx->switchContext('www-fr');
return $u;
}
// we are somewhere else…
else {
// …return an error (enhance later for > 2 lang)
return '#error';
}​
@rtripault
Copy link
Author

My first PHP code, so might be awful :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment