Created
November 12, 2010 04:19
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My first PHP code, so might be awful :/