-
☆ A M B ☆
- 24,524 Posts
That’s right. The chunk is evaluated and its content put in the snippet’s parameter value. So the snippet is still stuck at the =.
Quote from: sottwell at Sep 07, 2010, 03:21 AM
That’s right. The chunk is evaluated and its content put in the snippet’s parameter value. So the snippet is still stuck at the =.
You can pass just the chunk name as a snippet parameter (without the {{...}}) and then use $modx->getChunk($chunkName); inside the snippet and avoid that problem.
I’ve added the finial touches to the code:
<?php
/* Example snippet : [!langGet? &outputKer=`text here` &outputEng=`text here` &outputBilingual=`text here`!]
* &outputKer : output for Cornish titles
* &outputEng : output for English titles
* &outputBilingual : output for bilingual titles
*
* Example snippet : [!langGet? &titleKer=`pagetitle` &titleEng=`description !]
* &titleKer : MODx document varible for Cornish, use MODx varible names
* &titleEng : MODx document varible for English, use MODx varible names
*
* Example snippet : [!langGet? &chunkKerTpl=`chunk-name` &chunkEngTpl=`chunk-name` !]
* &chunkKerTpl : chunk used to show Cornish
* &chunkEngTpl : chunk used to show English
*/
$language = (isset($_GET['lang'])) ? $_GET['lang'] : (isset($_COOKIE['lang']) ? $_COOKIE['lang'] : 'eng');
$output='';
switch ($language){
case 'ker':
if(isset($chunkKerTpl)){
$output=$modx->getChunk($chunkKerTpl); // Show only chunk if set
} elseif (isset($titleKer)) {
$output=$modx->documentObject[$titleKer]; // Show title if set
} else {
$output=(isset($outputKer) ? $outputKer : ''); // Show output if if exists
};
setcookie ('lang', 'ker');
break;
case 'eng':
if(isset($chunkEngTpl)){
$output=$modx->getChunk($chunkEngTpl); // Show chunk if set
} elseif (isset($titleEng)) {
$output=$modx->documentObject[$titleEng]; // Show title if set
} else {
$output=(isset($outputEng) ? $outputEng : ''); // Show output if it exists
};
setcookie ('lang', 'eng');
break;
default:
if(isset($outputBilingual)) {
$output=$outputBilingual;
} elseif ((isset($chunkKerTpl)) && (isset($chunkEngTpl))) {
$output=$modx->getChunk($chunkEngTpl) . $modx->getChunk($chunkKerTpl); // Show only chunks if they are set
} elseif ($_COOKIE['lang'] == "ker") {
(isset($chunkKerTpl)) ? $output=$modx->getChunk($chunkKerTpl) : (isset($titleKer)) ? $output=$modx->documentObject[$titleKer] : (isset($outputKer)) ? $output=$outputKer : ''; // Show values for Cornish if set
} else {
(isset($chunkEngTpl)) ? $output=$modx->getChunk($chunkEngTpl) : (isset($titleEng)) ? $output=$modx->documentObject[$titleEng] : (isset($outputEng)) ? $output=$outputEng : ''; // Show values for English if set
};
};
return $output;
?>
Thanks for all the suggestions