I am trying to write a basic calendar snippet but the snippet documentation is somewhat sparse so I’m not sure about most things!
At the moment it is a php script where the view changes based on a GET variable:
calendar.php?view=display
calendar.php?view=addentry
Do snippets have access to all the $_GET, $_POST and $_SESSION variables like in a normal php script for this to work? If so, presumably I have to give the variables a very unique name otherwise I’d be clobbering other modx variables?
If I want to include the snippet in a page with the view already set can I do it like this?
[[calendar?view=display]] or [[calendar?view=addentry]]
Otherwise how do I pass variables to the script from within MODX?
Cheers!
hi,
change your snippet to uncached
[!calendar?view=display!]
:-)
Cheers,
So would [!calendar?view=display!] then put the value "display" into $_GET[’view’] ?
Changing your snippet call to uncache will allow you to acces from the code to $_GET and $_POST variables as usual.
So the view value will be set in the script and not as a param.
For instance:
$view = (isset($_GET[’view’])) ? $_GET[’view’] : "display";
hope that makes sense.
:-)
And I guess if you want to have different pages calling the same snippet with different preset views (before any user interaction), you could add this:
$presetView = (isset($presetView)) ? $presetView : 'display';
$view = (isset($_GET['view'])) ? $_GET['view'] : $presetView;
And then your snippet call could be something like
[! calendar? &presetView=`display` !]
EDIT: Oops! Tick marks changed from forward to backwards. ¡Damn my Späniçh keyboard!
Thankyou for the help, it is working of sorts now. I am getting other errors but going to start a new topic about them.
-
MODX Staff
- 12,272 Posts
Use back ticks, not forward ticks.
Ryan Thrash, MODX Co-Founder
Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me