Hi seems so simple, but I can’t find how to do it! How do you have a basic template with [[*content]] showing id one and then under show other docs in your resources such as id two, three etc. I want to have more than one piece of content shown in different parts of my html template. Is this possible? Surely it should be as simple as lower down putting [[*content_id2]] or something like that? Thanks.
use template variales for the other content areas
Thanks for the response. So is there no similar command to [*content] to show other pages in the template? It seems a bit awkward having to make TVs and then call inside those instead of just calling directly? It seems almost as easy to just copy it all in the html code?
there are many ways to get different html-blocks/areas into your page.
With Template-vars(TVs) you are able to insert code on different places to your Template.
And you can control the contents of them from page to page.
But you can of course also place snippets into your Template, which calls contents dynamically per php.
Two examples:
If you want to show content and other fields like pagetitle and so on from one or more other resources you would use getResources-snippet.
If you want to place single fields from other resources you can use the getResourceField-snippet.
hi thanks for the replies. All I would like to do is display resources in the same way the [*content] command does for the page id 1. How do I create a TV to display id2 or id3 etc in my template, to just show all the content of that resource without complicating anything too much? Thanks.
You’ve been given three answers already, Jonah. All of them work. All of them do the job described.
If you want to display four blocks of content - resource 1, 30, 40, 50; and on another page have resource 2, 40, 60, 80; you need to find some way of telling MODX what the conditional content is - whether it’s the children of the current resource, the next three alphabetically, the next three numberically, the next three in category, the next three as selected by the user......
So you need to tell it what to display (and where from) using either a template variable or a snippet/extra. You then need to format it (most snippets have default formatting, with the option for a specific).
In effect this ends up (in Revo pseudocode) as a series of snippet blocks:
[[$getotherresource? ¶m=`some_parameters` &tpl=`contentTpl`]]
with a template of [[*content]]
or
[[*myTemplateVar1]]
[[*myTemplateVar2]]
[[*myTemplateVar3]]
If instead of resources, what you simply want to do is reuse content, then you can use chunks instead
[[$chunk1]]
[[$chunk30]]
[[$chunk40]] etc, although this would mean changing the template each time - so you’d be better off using Template Variables for this approach.
Writer > E-consultant > MODx developer || Salesforce || modx 2.x || PHP 5.2.13 || MySQL client 5.0.86
Thanks again for your reply. I have tried as suggested using getresources. I’ve installed it from Package Manager.
I’ve inserted this in my template page code:
[[!getResources? &parents=`12` &includeContent=`1` &tpl=`myRowTpl`]]
I’ve made a template and put this in it:
<div class="myRowTpl">
[[+publishedon:strtotime:date=`%b %d %Y`]]
<h3>[[+pagetitle]]</h3>
<p> </p>[[+introtext]]
</div>
And I’ve made a page with the id12 with my content in and published it.
But it’s not displaying anything... Any errors in my code above? Thanks again for any help...
The one downside of getResources is that it only works for ’children’.
So you need to change:
[[!getResources? &parents=`12` &includeContent=`1` &tpl=`myRowTpl`]]
to
[[!getResources? &parents=`0` &resources=`12` &includeContent=`1` &tpl=`myRowTpl`]]
(or whatever the parent of 12 actually is)
or use getResourceField snippet, as suggested above (this particular snippet isn’t templated, so you’d surround it with your div class structure):
[[getResourceField? &id=`12` &field=`introtext`]]
Writer > E-consultant > MODx developer || Salesforce || modx 2.x || PHP 5.2.13 || MySQL client 5.0.86