Hi Chuck,
Here’s the best thing I can tell you to help you wrap your head around TVs: Forget the word TV and instead think of them as:
Custom Fields
That’s an oversimplification, but one that may make TVs easier to understand. You add any number of these custom fields (TVs) to your template, and then you can spit them back out in the resulting document in whatever form you want. Of course, it’s way more powerful than that, because you can also have the input of a custom field come not from the person editing/creating the document, but also from an external source like a text file or database call. And there are widgets to control the output of these custom fields as viewed in the page. But at their most basic, think of it as a way to capture user input in the editing interface and then to manipulate or display the information on the displayed page.
Here’s how we use the "No Subnavigation" TV:
First we set it up in the Template Variables interface to be a simple checkbox. The input option values are set to:
This page has no subnavigation==1
That means that if this checkbox is checked, the value will be 1.
Which results in the TV looking like this in the editing interface:
Then, at the top of all of our subsystem templates, we insert a simple snippet that checks the value of the noSubnav TV (custom field) to see if it’s set to 1. If so, it outputs some alternate CSS that removes the subnavigation from the page:
$fields=$modx->getTemplateVarOutput(array('noSubnav'),$modx->documentIdentifier,1);
$nosubnav=$fields['noSubnav'];
if ($nosubnav) {
return '<link rel="stylesheet" href="../_css/basic.css" type="text/css" />';
} else {
return;
}
So basically, when you apply a custom field (TV) to a template it can take input from the user or from an external source, and can display that input in the resulting document in any way you like, or you can use that input to programatically do something or display something else.
I hope this helps!
Cheers,
Andrew