Last active
January 24, 2022 20:24
-
-
Save 64j/fdc815ac88864254646959e1fd3d138c to your computer and use it in GitHub Desktop.
Snippet switch
This file contains hidden or 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 | |
| $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