Blog Sections Open

Auto-Filling an Empty TV from the Parent Resource

A manager-save pattern for inheriting a TV value from the parent resource when the child field is left empty.

Sometimes a child resource should inherit a TV value from its parent unless the editor explicitly overrides it. the discussion explored exactly that pattern using a manager event.

The basic idea

if ($modx->event->name == 'OnBeforeDocFormSave') {
    if (isset($tv_id) && (int)$tv_id > 0) {
        if ($_POST['tv1'] == '') {
            $parent_tv = $modx->getTemplateVarOutput([$tv_id], $parent);
            $_POST['tv1'] = $parent_tv['img'];
        }
    }
}

Why this is useful

  • shared defaults stay consistent across child resources
  • editors only fill the field when they need an exception
  • the tree can inherit media or metadata in a controlled way
Newer post

Using a Resource List TV and Returning a Real Link Label

A TV configuration guide for choosing resources efficiently in the manager while still outputting a proper link label instead of only the numeric resource ID.

Older post

Changing One TV Dynamically When Another TV Changes

A manager-side pattern for making one TV field react to another, useful when the second field depends on a section chosen in the first field.