16.03.2008
MODx-Feature:
Expanding documents with template variables
back to overview 2 Comments by Bogdan
For me, one of the most interesting features of MODx is the possibility to expand MODx documents with so called template variables. That way, you cannot only save content, title and a handful of meta specifications as usual, but also any number of information in different formats. These various applications are very versatile:
- costs for products
- images or files that are to be linked with the document
- keywords for blog entries
- further textual content of documents in addition to the main text
- …
Editing template variables
Let’s have a look on a document with template variables:
The template variables are added to the standard document contents and can be edited while emending the respective document.
Creating template variables
Creating template variables is relatively easy:
Template specific allocation
By the way, template variables are called template variables, as they can be allocated individually to each created template. Consequently, you can, for example, allocate the template article to the template variablesprice and overhead image and the template variables tags and also overhead image to the template blog entry. Thus, the template variables can be grouped accordingly to the content of a template.
Using template variables
Using template variables in HTML source code or in document contents is done by a MODx tag: [*tv-name*]:
Source code with template variables
<h2>Blog entries</h2> <ul> <li>[*pagetitle*]</li> <li>[*introtext]</li> <li>[*tags*]</li> </ul>
This basic example shows title, summary and tags for a blog entry while [*pagetitle*] and [*introtext*] are document specific template variables and only [*tags*] was added.
Types of entry
Template variables have got an entire list of types of entry which can be chosen according to the file that is to be saved:
As a result, you can conveniently choose the display and entry of the data in the manager and also change these later on.
@ bindings of template variables
Template variables can be provided with @ bindings. If, for example, a template variable has got the value @DOCUMENT 10 it will read the content of the document with the ID 10. Another interesting possibility arises from the the binding @SELECT, which allows SQL access to the MODx-SQL databank. This way, you can use @SELECT pagetitle FROM modx_site_content WHERE parent = 40to output all titles of the document with the ID 40 containing child documents in a template variable. The following @ bindings are available:
- @FILE
- @DIRECTORY
- @DOCUMENT
- @CHUNK
- @INHERIT
- @SELECT
- @EVAL
Endless opportunities
MODx documents can be flexibly upgraded with template variables so that not only classic website content can be presented, but also your own, freely definable data sets such as products, articles, addresses and so forth. This enables MODx users to save and then dynamically display information.






Write a comment
2 Comments
Bogdan visit website
24.12.2008 12:32:57
Hi Sitthykun!
Well that is actually pretty simple: if you select ‘image’ as entry type you get basically a text field and an insert button. Clicking the insert button opens an image browser that shows images and folders in your images folder which is located in assets/images/. Just choose an image and the image browser is closed and the path transfered to your TV. Of course you can type or change the path also manually.
In your template or chunk you can use the image TV like this:
<img src="" alt="Image TV sample">
Good luck,
Bogdan
Sitthykun visit website
24.12.2008 09:27:31
Hi,
how to use TV image?
…..