We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25478
    • 26 Posts
    how do you include snippets, say, "NewsPublisher" to a page? Please make your recommendation as simple as possible as I am new to modx and the documentation appears very complicated. I would very much appreciate A simple step-by-step procedure as it would do the trick. It makes tutorial easy to digest. Thanks.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Start here
      http://modxcms.com/template-basics.html
      then read the next page.
        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
        • 25478
        • 26 Posts
        i’m sorry but i cannot catch up . is there a simple way? a grammatically simple way? the way that hemingway writes his novel without using big words. that’s what i like to see in a tutorial.
          • 10746
          • 126 Posts
          Quote from: romyaspe at Nov 11, 2006, 06:31 AM

          how do you include snippets, say, "NewsPublisher" to a page? Please make your recommendation as simple as possible as I am new to modx and the documentation appears very complicated. I would very much appreciate A simple step-by-step procedure as it would do the trick. It makes tutorial easy to digest. Thanks.

          The question is hard to answer because it is not clear exactly what you are asking...

          At the most basic level, when you are creating a new content page, you can insert at any stage a special tag of the form

          [[SnippetName]]
          or
          [!SnippetName!]

          and when the page is parsed, that particular snippet will be executed and the tag will be replaced by the output of the snippet.

          Trouble is, most snippets have many parameters/arguments and are effectively programs in themselves (well, they ARE programs in themselves) and therefore there is often a learning curve in specifying the parameters so that the snippet does what you want it to do...


          So if we look at a very simple snippet like "DateTime" (the version on the repository, not the pre-installed one) then you can just enter something like

          Welcome to my website, it is now [!DateTime!].

          and your users will be greeted with something like

          Welcome to my website, it is now 11-11-2006 21:15:07.



          Of course, you probably don’t want that output, so you have to delve into the PHP syntax for formatting times and dates and then replace it with something like

          Welcome to my website on [!DateTime? &format=`%A %d %B`!].

          and then you get

          Welcome to my website on Saturday 11 November.

          Of course, in this example there is no logical processing performed by the snippet and so learning how to use the "format" argument is almost precisely as difficult as learning how to write the entire snippet

          More complex snippets like NewsPublisher or Ditto perform complex processing involving manipulating the entire MODx document tree and then produce some nice output for you - there is always a trade-off in that the more "customizable" the output, the more parameters you have to learn how to use, but at least you don’t have to learn how to search through the document tree, extract information from documents and so on.

          But the basic process is the same .. wherever you want the OUTPUT of the snippet to appear, you just include

          [[SnippetName]]
          or
          [!SnippetName!]

          along with any specific parameter values, and it will magically appear there.


          When to use [[ .. ]] or [! .. !] ?

          The difference is to do with caching.. if you use [[ .. ]] then that indicates that the content is suitable for caching, so that a subsequent request to the same page within a short while will just get the same page without having it re-parsed. If you use [!.. !] then it will be re-executed and the new value inserted

          Obviously for times, a cached copy of the page won’t do, but for many things (menus, blogs etc) it doesn’t matter.

          Hope this helps..

          Gordon

          PS I am a very new user and it took me a while to separate the logic of templates / snippets / chunks and so on.




            • 33337
            • 3,975 Posts
            Very nice little tutorial Gordon! very nice! smiley

            Can you post this to our new wiki: http://wiki.modxcms.com under "How To" section?

            best regards,

            zi
              Zaigham R - MODX Professional | Skype | Email | Twitter

              Digging the interwebs for #MODX gems and bringing it to you. modx.link
              • 25478
              • 26 Posts
              Very nice indeed!

              Thank you!

              I hope we have tutorials like this one: simple, straight to the point. Just like the philosophy of ernest hemingway - you don’t need big words to create a great novel.

              If only we can simplify the complex tutorials, MODx will be in for a great, great adventure.
                • 10746
                • 126 Posts
                Quote from: zi at Nov 11, 2006, 07:49 AM

                Very nice little tutorial Gordon! very nice! smiley

                Can you post this to our new wiki: http://wiki.modxcms.com under "How To" section?

                I would happily do so, except that I cannot figure out how to create a new article... I can see how to "edit" an existing article, but I just can’t find a "New" button anywhere...

                I searched the "help" and it told me about the editing syntax, and so did the Sandbox, but not about new pages..

                Gordon
                  • 14488
                  • 4 Posts
                  Quote from: gfroyle at Nov 13, 2006, 06:09 PM

                  I just can’t find a "New" button anywhere...

                  Thats a great description of snippets Gordon, I’ve got dyslexia and need to constantly remind myself of things like that and you have explained it extremely well.

                  From my recollection of Wiki’s to create a new page I think you need to edit the "HOWTO" page first and put in a link to the page you haven’t created yet, then follow that link and you should end up on an editor page that says "This page hasn’t been created yet" (or similar) with an RTE for the content.
                    John Blackmore
                    www.club-306.com
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    Or you can just enter the URL to the page you will be creating (make sure there isn’t another page already with the name you want to use) and it will open to a new page for editing. You can assign it to a section later.
                      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