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.