Template Variables is one thing that sets MODx apart from other CMS’s.
What is a template variable?
Think of "TV’s" as document objects. Expression Engine calls them "Custom Entry Fields".
From Expression Engine:
"Custom Entry Fields
Each weblog can have its own unique set of entry fields. These can be input boxes, pull-down menus or textareas."
The difference: TV’s have much more flexibility. TV’s are Custom Entry Fields that can be any of the following:
- Pull-down menu
- Checkbox
- File
- Text (Input box)
- Textarea
- Rich text area
- Listbox (single-select)
- Listbox (multiple-select)
- URL
- Email
- Date
- Number
Also, you have multiple ways to display the input in these fields such as:
- DataGrid
- Floating Div
- Marquee
- Ticker
- IFrame
So what does this mean? Let’s say you have a client that needs to create pages that have a Title, Author, Content, Custom Image header, Start Date, End Date, and 4 custom fields named Where, Who, Why, How.
With MODx TV’s, you don’t hack your way around and telling your customer to create a table and fill in the items where they go. Instead you create the following TV’s (or document objects).
1. TV #1
- name: tvImageHeader
- input Type: File
- Widget: Image
- Default Value: (If you need a default Image)
2. TV#2
- name: tvStartDate
- input Type: Date
- Widget: Date Formatter
3. TV #3
- name: tvEndDate
- input Type: Date
- Widget: Date Formatter
4. TV #4
- name: tvWhere
- input Type: text
- Default Value: (if needed)
5. TV #5
- name: tvWho
- input Type: text
- Default Value: (if needed)
6. TV #6
- name: tvWhy
- input Type: text
- Default Value: (if needed)
7. TV #7
- name: tvHow
- input Type: text
- Default Value: (if needed)
Why would I use these?
When you use TV’s, the content creator does not have to bother with HTML formatting or design.
How do I use these then?
In your template (or ditto), you will place these TV’s as placeholders where you want them to appear, and MODx will fill in the details for you.
Example:
<div class="ImageHeader>[*tvImageHeader*]</div>
<h1>[*title*]</h1>
<p>[*createdby*]</p>
<div class="myContent">
[*content*]
</div>
<div class="furtherDetails">
<p>When: [*tvStartDate*] to [*tvEndDate*]</p>
<p>Where: [*tvWhere*]</p>
<p>Who: [*tvWho*]</p>
<p>Why: [*tvWhy*]</p>
<p>How: [*tvHow*]</p>
</div>
Now the content creator does not ever have to deal with how the site looks. You create the fields they need, they fill them out, and the page will populate to look as pretty as you want it to be.
I hope this helps some people (switch from Expression Engine) and understand TV’s. They give you, the designer or developer, a great flexibility for your clients or content creators.
Chuck