My understanding of the MODx framework seems to grow with every project we complete here at Pleth. It seems I am always learning to appreciate new aspects of this system and how the components can interplay to open up possibilities for each new project. Here lately I have been surprised to discover how powerful the template can be in MODx.
I, like most developers, started off thinking of a template as the repository for the structural HTML (which it is), but with MODx so much more is possible by associating different components with the template(s).
Template Variables
Template Variables (TVs) are a tool for adding custom fields that can be assigned to a single or even multiple templates. These fields are then viewed/accessed when editing a document that is assigned to a particular template which then owns a particular TV.
Template Variables are one of the most powerful features of MODx dynamic content generation. At their simplest, they can be considered extensions to the existing document variables, such as pagetitle, longtitle and content. Custom fields, as it were. But they can go far beyond that, querying the database or processing PHP code.
If you are new to MODx TVs are one of the first places to start as they can unlock so much potential for your site.
Document Object
Once you have mastered taking advantage of MODx TVs you can move into a powerful feature like the Document Object array. By harnessing these document-specific variables it is possible to access the template IDs (unique numeral identifying each template).
I have recently used this angle to create a snippet which returns the template ID and then goes through a series of arguments (if else statements) to return results dependent on which template is use in that document.
<?php
$TempId = $modx->documentObject['template'];
if ($TempId=="4")
$output="{{contentOne}}";
elseif ($TempId=="6")
$output="{{contentTwo}}";
elseif ($TempId=="9")
$output="{{contentThree}}";
else
$output="{{contentFour}}";
return "$output";
?>
ManagerManager Plugin
When used in combination with document TVs and techniques like the one above the ManagerManager plugin allows the developer to further release the power of MODx templates.
ManagerManager allows you to:Change field namesHide fieldsChange the help text for fieldsRename tabsHide tabsCreate new tabsMove fields to different tabsInherit field values from parent documentsPrefill date values with customisable valuesLink fields together so their values always matchRename and move sections of the document editing pageAdd widgets to Manager fields – e.g. Del.icio.us-like tag interface, color picker, image preview.
All these features can be enabled for any manager role, any template, or any combination of these.
With this, it is possible to create custom, field driven templates that exclude any unnecessary fields and include customized labeling.
As I mentioned at the onset my own MODx, skill level continues to increase with each project. That is the beauty of a framework like MODx, it has something to offer developers at many skill levels while being appropriate for small and large projects alike.




Pingback: gigoxityme