We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32219
    • 7 Posts
    every time i add a new snippet. I call it n it produces the whole snippet code.Is it that i dont use any snippet parameters or what?
      • 27708 MODX Staff
      • 2,502 Posts
      Please show me the page, chunk or template code that includes the call for the snippet. Also, have you actually written a snippet? If so please show the code.

      One thing about snippets is that as of MODx 0.9.5 (I think; 0.9.6 for sure) you have to have the php open/close as part of the snippet code so snippets in the snippet section of Resources must begin with <?php and end with ?> otherwise MODx will treat it as a string and just show the code.

        Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
        • 32219
        • 7 Posts
        Thanks a lot for the references...I’ll try my hands on them.Anyway I want to know how publish news stories on my page.How do i call the news publisher in my site
          • 3749
          • 24,544 Posts
          Quote from: weezy at Sep 27, 2007, 06:48 AM

          every time i add a new snippet. I call it n it produces the whole snippet code.Is it that i dont use any snippet parameters or what?


          From the MODx 101 section of the forum:

          [FAQ] My snippet call isn’t working ...
          « on: Jan 05, 2007, 08:59 AM » Quote

          --------------------------------------------------------------------------------
          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.
          --------------



          Bob
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 27708 MODX Staff
            • 2,502 Posts
            Quote from: weezy at Sep 27, 2007, 11:51 AM

            Thanks a lot for the references...I’ll try my hands on them.Anyway I want to know how publish news stories on my page.How do i call the news publisher in my site

            Create a new page.
            place [[NewsPublisher]] on the page.
            Save.

            There are parameters listed in the Resources->Manage Resources->Snippets->NewsPublisher.

            To call with parameters just change the above to:

            [[NewsPublisher?&paramName=`paramValue`]]

            This is the same syntax for ALL snippets. Just stick the snippet name in double square brackets. Some snippets will require that they be uncached and therefore you replace the inner square brackets with exclamation points. Again the syntax for calling snippets is the same.

            Jay
              Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
              • 3749
              • 24,544 Posts
              Weezy,

              It might help if I explain what a snippet is.

              A snippet, for someone starting out like you, is just a thing written by someone else that does some stuff and puts it on the page where you put the snippet call. It does this automatically when a user visits that page.

              With the NewsPublisher snippet, for example, you create a new MODx document in the manager. Then you put the following snippet call on that page:

              [[NewsPublisher]]

              When the user visits that page, MODx sees the snippet call, looks for a snippet with that name, and then executes the code in that snippet. The NewsPublisher snippet code prints out a form on the page that lets the user add a news item and submit it to be saved. That form is all the user sees when the page is shown in his or her browser.

              Most snippets take parameters, as mentioned in SmashingRed’s post. These tell the snippet how to behave. The NewsPublisher parameter &folder, for example, tells the snippet where to put the news story.

              If the container document you created to hold your news stories has the page ID of 7 (you can see the document number by looking at the document tree at the left side of the manager screen), you would put

              [[NewsPublisher? &folder=`7`]] as your snippet call.

              You should never change the code in a snippet itself unless you really know what you are doing and, most of the time, you don’t need to understand the code inside the snippet. You just call it with the right parameters and it works.

              Bob

                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 27708 MODX Staff
                • 2,502 Posts
                To add to BobRay’s words--to make it absolutely clear--Snippets are PHP scripts or parts of php scripts that can be "processed" by the server and MODx that extends MODx beyond its basic installed functionality.

                  Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub