We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Probably the biggest recurring problem with snippets is that users overlook the syntax of calling snippets. Here’s two basic guidelines:

    [*] Use backticks around your parameters, not single-quotes: &param=`foo`
    [*] If you are working with a snippet that needs to process a form, always call it uncached: [!snippet?param1=`foo` &param2=`bar`!] (or put it on a document that is set to not be cached in the Page Settings tab)
    [*] If your page simply prints the snippet call rather than executing it, check the spelling and case of your snippet name in the call and make sure it matches the actual name of the snippet. Snippet names are case-sensitive.
    [*] If the parameters in your snippet call are not reaching your snippet, make sure there are no spaces around the equals signs in the call.

    Wrong: [[SnippetName? &param = `value`]] (note the extra space around the equals signs)
    Right: [[SnippetName? &param=`value`]]
      Ryan Thrash, MODX Co-Founder
      Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
      • 7260
      • 107 Posts
      heh...thanks for that one!

      I was just going to ask...strange thing though..some of my calls work without a tick at all. Found weird.
      Backticks..yeah. NOT single quotes...doh!

      • Quote from: DfX at Jan 13, 2007, 02:22 AM

        heh...thanks for that one!

        I was just going to ask...strange thing though..some of my calls work without a tick at all. Found weird.
        Backticks..yeah. NOT single quotes...doh!

        The backticks are optional, but are a good best practice to follow, as they were designed to allow extra whitespace between your snippet parameter values. This is so snippet tags with long parameters strings wrap in the editors.

        Consider these tags and resulting extracted variables...
        [[snippet?foo=bar &foo2=bar2]]
        would result in:
        $foo == 'bar ';
        $foo2 == 'bar2';

        [[snippet?foo=`bar` &foo2=`bar2`]]
        would be:
        $foo == 'bar';
        $foo2 == 'bar2';
          • 14234
          • 6 Posts
          So what do you make of this:
          [!NewsPuplisher? &folder=``13 &makefolder=`1`!]

          results: nothing is displayed
            • 15082
            • 195 Posts
            Should’nt this be
            [tt][!NewsPublisher? &folder=`13` &makefolder=`1`!][/tt]

            2nd thought: Are you by any chance running a fresh install of MODx 1.0.1?
            IIRC NewsPublisher is’nt any longer bundled with the core...


            EDIT @JJJames: Please don’t double post that way wink
              • 27731
              • 9 Posts
              I experience exactly this error - I get the code rendered instead of the code executed. See pic below.

              The text which is presented comes from about 60% into the code. I’ve tried to understand why it starts to produce this output at this point instead of executing... but unfortunately I do not have the full knowledge of coding.

              I’ve got this code from this thread:

              http://modxcms.com/forums/index.php/topic,9617.0.html (on page 6 I think)

              The snippet call looks like this:


              Why does it not work...?

              Thanks a lot in advance for replies!
              • Once again, please do not double-post; I answered your question in the thread for Kalendar.
                  • 23430
                  • 10 Posts
                  Apologies for the cross post, but I got no replies to my post from 3 weeks ago on the GoogleEvents support thread, and I don’t know if my problem is related to that particular app or a more generic snippet problem...

                  GoogleEvents looks ideal for displaying the rehearsal and concert schedule on our big band’s web site, that I’ve taken over and built in MODx 1.0.2, but I can’t get it to display anything on the page. I’m sure I must be doing something very simple wrong. The call I’m currently using is this:


                  I’ve tried adding in spaces between parameters, taking them out etc. but all I’m seeing on the page is the title that I’ve put in as text, not even an error message or the text of the snippet call. Any ideas?

                  A possibly related question is this: the readme instructions give the parameters and sample snippets followed by a list of placeholders, separated by the (to me) intriguing sentence

                  The placeholders that you can use in the chunks passed to the snippet for a template are:

                  Does this mean the snippet won’t work without using chunks that I’d have to code myself? Is this the "something obvious" I’m missing?

                  I don’t know if it’s relevant, but another snippet on another page (SimpleSlideShow) has also suddenly stopped working - well I say stopped working, but actually the page is defaulting to the home page (presumably an error and I have return to home page in the event of an error set in the config). All I have done is add the installation/site sub-directory to .htaccess and set the site ready to use friendly URLs

                  Thank you very much in advance!