What are Templates?
Templates typically contain the HTML markup tags that determine the layout and appearance of your site. When a document is requested, MODx loads the document and its template, and MODx finds all the special placeholders in the template and replaces them with the corresponding values from the document before sending the finished page off to the user's browser.
Think of a Template like a house. Your Resource's content, then, is a person. A person can have many different houses, but only live in one house at a time.
Resources can only use one Template at a time, however, a Resource can switch Templates at any time, just as a person can move from house to house at any time. The Template, just like a house, also changes the main way a page is displayed. A Template usually contains the header and footer of a page - and/or a sidebar, navigation bar, etc.
To create a Template -- Expand the "Elements" part of the tree and right click on Templates. Select "Create a New Template" then paste your HTML into the "Template Code" textarea; you can copy and paste the text below to get started with a very simple template:
<html> <head> <title>[[*pagetitle]]</title> <meta name="description" content="[[*description]]"/> </head> <body> <h1>[[*longtitle]]</h1> Page ID: [[*id]]<br/> IntroText (Summary): [[*introtext]]<br/> MenuTitle: [[*menutitle]] <hr/> [[*content]] </body> </html>
Note the important [[*content]] tag; this tag tells MODx where to put the Resource's content.
MODX defaults to storing templates in its database, if you are using a version prior to 2.2.x this is your only option. In MODX 2.2.x and newer you have the option of storing templates as static files using Media Sources.
Remember that simply creating a template doesn't mean that it is automatically put to use: you have to edit each Resources and specify which Template it uses. This is different from some content management systems where each template has one or many pages. Each MODx page has a single Template that it uses to format output.
After you've created one or more Templates, you can edit any Resource and choose a Template for it by selecting one from the "Uses Template" drop-down list.
Using Resource Fields in the Template
As you noticed from our Template sample code above, the fields of a Resource can be referenced using the [[*fieldName]] syntax. A list of available Resource Fields can be found here. For example, if we wanted to show the current Resource's pagetitle in our