Sorry, I’m a newbie. How do I evaluate a template variable in php to use it in a logic statement?
simplified example:
// calling function from a chunk
[[mysnippet?myvar="[*my_template_var*]"]] //my_template_var has a default value of 1
// mysnippet code
echo $myvar; // outputs "[*myvar*]" to the output file, then modx evalutes it to 1 and replaces [*myvar*] in the output file with 1
$x = (int)$myvar; // x is 0 because myvar containts "[*myvar*]", not 1
if ($x == 1) { // always evaluates false
echo ’1’;
} else {
echo ’0’;
}
?>
-
☆ A M B ☆
- 24,524 Posts
Snippet parameters are not surrounded with quote marks, rather with backticks `value`.
You can deal with TVs programmatically within snippets using the API function
$myvar = $modx->getTemplateVar
http://wiki.modxcms.com/index.php/API:getTemplateVar