We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18409
    • 54 Posts
    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!
      • 11975
      • 2,542 Posts
      hi,

      change your snippet to uncached

      [!calendar?view=display!]

      :-)
        Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
        • 18409
        • 54 Posts
        Cheers,

        So would [!calendar?view=display!] then put the value "display" into $_GET[’view’] ?

          • 11975
          • 2,542 Posts
          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.

          :-)
            Made with MODx : [url=http://www.copadel.com]copadel, fruits et l
            • 33372
            • 1,611 Posts
            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!
              "Things are not what they appear to be; nor are they otherwise." - Buddha

              "Well, gee, Buddha - that wasn't very helpful..." - ZAP

              Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
              • 18409
              • 54 Posts
              Thankyou for the help, it is working of sorts now. I am getting other errors but going to start a new topic about them.
                • 25663 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