We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32645
    • 377 Posts
    I’ve done a search and found that it is "possible" to create functions in snippets, but I don’t know how to call them.

    I’m wanting to create one snippet for all my drop down boxes.

    ie:
    // How do I call snippet functions from my pages, or even within snippets?
    function pickDate($filter_date)
    function pickMonth($filter_month)
    function pickYear($filter_year)
    
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Like you would use functions in any .php file. The only difference is that you’ll need to have
      global $modx

      at the beginning of your function code. So in a snippet you’ll have
      function myFunc($args) {
      global $modx;
      // function code
      }

        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 32645
        • 377 Posts
        That’s not what I meant.

        I meant in the actual pages.

        // On some page, or another chunk
        // the name of the snippet is datestuff
        // but how do I call a function from this point?
        [[datestuff]]
        
          • 7231
          • 4,205 Posts
          You will need to add a logic layer to call the function from the snippet call:

          [!snippet? &function=`daestuff`!]
            [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

            Something is happening here, but you don't know what it is.
            Do you, Mr. Jones? - [bob dylan]
            • 32645
            • 377 Posts
            Ah! Okay, I’ll try it out.

            Thanks