Your template contains a lot of informations that must be present in only one place... (ie, all the informations inside the <head></head> tags, and many others).
Snippets like getResources or Ditto, have as objective to list all or part of resources... So you have a list with Resource 1, Resource 2, Resource 3 etc, each with their specific contents...
Your template is the FULL page (not only content, but the head tags as explain below, and all the snippets and routine you have placed in this template)
It would be impossible to have all the full pages, side by side on a same page !
Other reason is that you should not want to display all the content but only a part of it (only the content field, or only the introtext) in the list you display via Ditto or GetResource...
Hope it will help you to understand...
Cheers
-
☆ A M B ☆
- 24,524 Posts
It’s different templates. The "template" is the HTML structure for your page, MODx uses it to generate your entire web page. The Ditto/Wayfinder/getResources "tpl" is a mini-template that the snippet itself uses when processing each resource in its list of resources. It has nothing to do with the MODx main template, nor does MODx concern itself with the snippet’s tpl.
Consider what the snippet is doing. It’s given a list of resources to work with. It loops through these resources, and for each one applies the mini-tpl you specified. Its final output is then inserted into the main MODx template where the snippet call is positioned, actually MODx replaces the snippet tags with the snippet’s output. Yes, it’s a template in both cases, but they serve two totally different masters.
The difference between [[*value]] and [[+value]] is closely related. [[*value]] is for the variable associated with the page being generated. It will always refer to that value. So if you have a page with a getResources snippet call, [[*value]] will always be the value related to that page.
[[+value]] is perhaps the same variable, but it applies to the resource that the snippet is processing as it loops through its list of resources. So its actual value will (most likely) be different for each resource as the snippet loops over them. The snippet loads the placeholder array with the values for that reasource, then applies its mini-tpl to the resource, replacing the placeholders with the values for the field for that resource.
If you have resource #3, "News", with a getResources snippet, then [[*pagetitle]] will always be "News". And the template will be the one assigned to resource #3.
News has children, each one an individual news item. Say #45 "We Won", #46 "We Lost", #47 "A Tie". GetResources is told to use #3, "News", as the parent or startId for generating its list of news items. It is told to use a certain chunk as its mini-tpl for each news item in its list. In that mini-tpl, you have [[*pagetitle]] - Item [[+id]] "[[+pagetitle]]". This will produce a list with
News - Item 45 "We Won"
News - Item 46 "We Lost"
News - Item 47 "A Tie"
So [[*value]] is, again, related to the resource for the full page being generated by MODx. [[+value]] is created by a snippet, and relates to whatever it is the snippet is doing.
Well I’m reading and re-reading this and I still find it foggy !
Why do I have to create a template at first to be able to associate TVs to my resources, then have to use another template (chunk) for the output ? I really don’t understand why modx doesn’t "simply" allow using the template associated to the resource.
You say that the template is the structure for the page, but why not use "sub-templates" containing only the minimum required ? A template may contain a whole page structure/layout but could also contain only the formatting elements for the resources using it !?
In your example if I have a News page using a NewsPageTpl template with full html/head/body, why not have the 3 children use a NewTpl template containing only the minimum html markup (for example <div class="newsformat">[[*content]]</div> with associated TVs ? All the templating could be done in one place instead of having to switch constantly between chunks and templates, and it would remove a lot of confusion between placeholders/TVs/extra-notations for TVs. If one needs to access the parent pagetitle, then he would explicitly ask for it in some way. I’m very disturbed by all this back and forth switching, in my mind as well as in the backend UI (which by the way is sometimes slow and has refresh problems and makes the experience somewhat unpleasant) !
-
☆ A M B ☆
- 24,524 Posts
In your example if I have a News page using a NewsPageTpl template with full html/head/body, why not have the 3 children use a NewTpl template containing only the minimum html markup (for example <div class="newsformat">[[*content]]</div> with associated TVs ? All the templating could be done in one place instead of having to switch constantly between chunks and templates, and it would remove a lot of confusion between placeholders/TVs/extra-notations for TVs.
Then how would you display the full news item (from a Read more... link in the getResources list on the main News page). The getResources has to know how you want that list of news items laid out on the main News page. MODx has to know how you want the main News page to look, and it will also need to know how you’ll want the individual news item pages to look. Different but similar tools for different purposes. I need a 5-pound sledge hammer to split oak logs, but I need a tack hammer for securing the backing onto a picture frame.
Trust me, it will become clear in time, once you are able to clearly separate the different processing going on, one step at a time.
The NewsTpl associated with the resource could be the default one, and then there could be a FullNewsTpl to pass as parameter when needed.
Well, I hope I will be able to get around it, modx has been existing for a few years so if things are the way they are it’s probably for a good reason...
This is why I’ve been nagging people to call templates templates and to call the template-like chunks (which are *not* templates in MODx) Tpl chunks.
Templates are a specific type of element and they are not chunks. Likewise, chunks (no matter what they do) are not MODx templates.
Templates are full page templates with a DOCTYPE, <html>, <head>, and <body> tags. They are required for any regular web page.
Tpl chunks are just for formatting smaller bits of page content and shouldn’t contain any of the tags listed above. They are optional and any web page could be produced without them. Their advantage is that they help you separate the content from the HTML used to display it.