On the values of TVs and the @INHERIT binding
There are three ways to fetch the value of a TV from within a snippet.
First you need the TV as an object, and the id of the actual resource:
$tv = $modx->getObject('modTemplateVar',array('name'=>'tvName'));
$res_id = $modx->resource->get('id')
This code gets the raw value of the TV:
$rawval = $tv->getValue($res_id);
This code gets the rendered output of the TV:
$rendered = $tv->renderOutput($res_id);
A shorter form to get the rendered output is:
$value = $modx->resource->getTVValue('tvName');or
$value = $modx->resource->getTVValue($tvId);
if $tvId is the ID of the TV in the Elements tree.
Assume a TV of
- Input type Checkbox
- Input Option Values 1||2
- Default Value @INHERIT
- Output type Delimiter with Delimiter , (comma).
and assume these resources:
using the same template the TV is assigned to.
Then you will get these results:
Checked boxes | Raw TV value | Rendered TV value | Raw TV value | Rendered TV value
on Main Page | on Main Page | on Main Page | on Sub Page | on Sub Page
none @INHERIT empty string @INHERIT empty string
1 1 1 @INHERIT 1
2 2 2 @INHERIT 2
1 and 2 1||2 1,2 @INHERIT 1,2
Editing the Sub Page, if you change the Checkboxes on the TVs tab, the new value will override the inherited value. If you set them back to the inherited value, the Raw value will switch back to @INHERIT again.