I have created the following snippet because I have several docs that handle arbitrary http parameters, and I wanted to simplify accessing them
<?php
/* Get - Simple access on http parameters
*
* Parameters:
* ¶m (mandatory) - name of the GET- or POST-variable
* &ph (optional) - instead of simply returning the value, set a placeholder of the name given
* &default (optional) - return or set placeholder to this value given, if parameter is not set or empty
*/
$val = $_REQUEST[$param];
if ( !isset($val) ) {
if ( !isset($default) ) return;
else $val = $default;
}
if ( $ph ) {
global $modx;
$modx->setPlaceholder( $ph, $val );
return;
}
else { return $val; }
?>
In contradiction to my understanding of the modx caching mechanism so far, this snippet only works when called cached: [[Get? ... - no matter whether or not caching is activated for the document. Thought that [[...]] depends on whether the document caching is active or not, whereas [!...!] is always called uncached independently of the setting.
Sample code:
[[Get? ¶m=`domain` &ph=`domain` &default=`` ]]
<p>[+phx:if=`[+domain+]`:ifempty=`empty`+]</p>
sample urls: A /index.php?id=123 and B /index.php?id=123&domain=8
doc cache active, cached call, A -> "empty"
doc cache active, cached call, B -> "8"
doc cache inactive, cached call, A -> "empty",
doc cache inactive, cached call, B -> "8",
doc cache active, uncached call, A -> "empty",
doc cache active, uncached call, B -> "empty",
doc cache inactive, uncached call, A -> "empty",
doc cache inactive, uncached call, B -> "empty",
Could you explain this odd behaviour to me? Are there any subtleties in the implementation of my snippet?
Thanks for illumination
in advance.