MODX Template Variables (TV) Setup
Template Variables are additional resource fields in MODX. They allow adding arbitrary data to pages: images, prices, dates, dropdowns, galleries, text blocks. Each TV is bound to one or more templates.
TV Types and Usage
| Type | Usage |
|---|---|
| Text | Short text field |
| Textarea | Multi-line text |
| RichText | WYSIWYG editor |
| Number | Numeric field (price, quantity) |
| Date | Date with calendar |
| Image | Image selection from media browser |
| File | File upload or selection |
| URL | Link |
| Email with validation | |
| Checkbox | Single checkbox (yes/no) |
| Listbox (single) | Dropdown |
| Listbox (multi) | Multiple selection |
| Radio Options | Radio buttons |
| Tag | Tags separated by comma |
| autotag | Auto-complete from existing tags |
| migxdb | Complex structure (MIGX) |
Creating TV via Manager
Elements → Template Variables → Create:
-
Name:
product_price(Latin only, underscores) -
Caption:
Price(displayed in editor) - Input Type: Number
-
Default Value:
0 - Templates: select templates where field should appear
- Access Tab: field order in interface, field group
Input Types with Settings
Listbox (Single) — Dropdown:
Input Type: Listbox (Single)
Input Options:
Color==Color||Size==Size||Weight==Weight
Or from database:
@SELECT `id`, `name` FROM `site_content` WHERE `template`=5 AND `published`=1
Image with media browser restriction:
Input Type: Image
Input Options:
[[++base_url]]assets/images/products/
Checkbox group:
Input Options:
monday==Monday||tuesday==Tuesday||wednesday==Wednesday||thursday==Thursday||friday==Friday
Output Type: delim (values separated by ||)
Displaying TV in Template
[[- Basic output ]]
[[*product_price]]
[[- With formatting ]]
[[*product_price:number_format=`0,.`, ` `]] ₽
[[- Conditional output ]]
[[*product_image:notempty=`<img src="[[*product_image]]" alt="[[*pagetitle]]">`]]
[[- With phpthumb ]]
[[*product_image:phpthumb=`w=800,h=600,zc=1`]]
[[- File link ]]
[[*product_brochure:notempty=`<a href="[[*product_brochure]]" class="btn">Download Brochure</a>`]]
Getting TV via Snippet
// Get TV programmatically
$resource = $modx->getObject('modResource', $resourceId);
$price = $resource->getTVValue('product_price');
$image = $resource->getTVValue('product_image');
// Set TV programmatically
$resource->setTVValue('product_price', 1500);
TV Organization via FastTab
FastTab allows grouping TVs by tabs in resource editor:
Tab "SEO": seo_title, seo_description, seo_robots
Tab "Product": product_price, product_sku, product_weight
Tab "Gallery": gallery (MIGX)
Tab "Content": hero_image, hero_text, features_json
Checking TV Completion
// In snippet — check completion before output
$tvValue = $resource->getTVValue('important_field');
if (empty($tvValue)) {
$modx->log(modX::LOG_LEVEL_WARN, "TV important_field empty for resource {$resource->id}");
}
Timeline
Creating and configuring 10–20 TVs for project with template binding and FastTab grouping — 3–5 hours.







