Skip to content

Instantly share code, notes, and snippets.

@64j
Last active January 24, 2022 20:24
Show Gist options
  • Select an option

  • Save 64j/fdc815ac88864254646959e1fd3d138c to your computer and use it in GitHub Desktop.

Select an option

Save 64j/fdc815ac88864254646959e1fd3d138c to your computer and use it in GitHub Desktop.
Snippet switch
<?php
$switch = !empty($switch) ? $switch : '';
$default = !empty($default) ? $default : '';
$out = '';
if (!empty($params)) {
$out = $default;
foreach($params as $k => $v) {
$value = mb_substr($k, 5);
if (mb_substr($k, 0, 5) === 'case:' && $value === $switch) {
$out = $v;
continue;
}
}
return $out != '' ? $this->parseText($modx->getTpl($out)) : '';
}
/*
[[switch?
&switch=`[*content*]`
&case:=`@CODE: --- CONTENT IS EMPTY ---`
&case:123=`@CODE: -- CONTENT IS 123 ---`
&default=`@CODE:<div>[*content*]</div>`
]]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment