Quote from: jbjoe at Mar 05, 2010, 07:54 PM
how do you pass $_POST and $_GET variables to snippets (or chunks)? Is there a standard way to do this? Do I have to develop a special snippet for this myself?
All snippets have access to GPC variables as they would in any PHP script. You don’t have to "pass" anything. As for chunks, in Revolution you can pass properties to a chunks, but again, you should use a snippet to access any GPC variables:
<?php
/* process a chunk with the $_REQUEST vars as placeholders */
$output = $modx->getChunk('myChunk', $_REQUEST);
?>
though something like this is also possible:
[[!$myChunk? &myPostVar=`[[!getValue? &var=`_GET` &key=`myPostVar`]]`]]
where getValue is a snippet like such:
<?php
/*
getValue: an example snippet to get a scalar variable value
or optionally a scalar array entry (specify key)
PROPERTIES:
&var - the name of the scalar variable or array to get a value from
&key - the index key of an array variable specified in &var; required if &var is an array
*/
$value = '';
if (!empty($var) && isset($$var)) {
if (is_scalar($$var)) {
$value = (string) $$var;
}
if (is_array($$var) && !empty($key) && array_key_exists($key, $$var)) {
if (is_scalar($$var[$key])) {
$value = (string) $$var[$key];
}
}
}
return $value;
?>