Last active
April 10, 2020 16:24
-
-
Save matdave/0786a6a990408bf428513ca0cd237415 to your computer and use it in GitHub Desktop.
MODX codeSamples
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 | |
/** | |
* codeSample Snippet for rendering ASCII characters of element calls in MODX frontend | |
* e.g. | |
* [[codeSample?&element=`QuickEmail`&properties=`debug=1` &cachedFlag=`true`]] | |
* outputs [[!QuickEmail? &debug=`1`]] | |
**/ | |
$element = $modx->getOption('element', $scriptProperties, null); | |
$type = $modx->getOption('elementClass', $scriptProperties, 'modSnippet'); | |
$cachedFlag = $modx->getOption('cachedFlag', $scriptProperties, false); | |
$properties = $modx->getOption('properties', $scriptProperties, null); | |
$output = null; | |
if(!empty($element)){ | |
$output = "[["; | |
$output .= ($cachedFlag) ? "!" : ""; | |
switch($type){ | |
case "snippet": | |
case "modSnippet": | |
break; | |
case "chunk": | |
case "modChunk": | |
$output .= "$"; | |
break; | |
case "resource": | |
case "modResource": | |
$output .= "~"; | |
break; | |
case "variable": | |
case "tv": | |
case "modTemplateVariable": | |
$output .= "*"; | |
break; | |
case "placeholder": | |
$output .= "+"; | |
break; | |
} | |
$output .= $element; | |
$properties = explode(",",$properties); | |
if(!empty($properties)){ | |
$output .= "?"; | |
foreach($properties as $property){ | |
$property = explode("=",$property); | |
$output .= " &".$property[0]."=`".$property[1]."`"; | |
} | |
} | |
$output .= "]]"; | |
} | |
return $output; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment