Hello
I’m new to MODx and trying to convert a legacy system to run within it.
I understand that I must put php into snippets for them to run, but then I have two snippets on the page and they do not share variable space. For (a simple) example:
Snippet1
<?php
$a = "hello";
echo $a;
?>
Snippet2
<?php
echo $a;
?>
and in the template I do:
[!Snippet1!]
[!Snippet2!]
then the value of $a is lost for the second call.
How do I pass this (and preferably any other) php variable? Or is there a better way around this?
Thanks in advance!
-
MODX Staff
- 10,725 Posts
Use placeholders. It’s an array for storing (and sharing) variables within the scope of single MODx request. It is an object variable on the $modx object.
One way to do what Jason recommends is to use
setPlaceholder in your first snippet and
getPlaceholder in your second.
That works, too (as does the $_SESSION array).