Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save fomigo/2344301 to your computer and use it in GitHub Desktop.
Save fomigo/2344301 to your computer and use it in GitHub Desktop.
Default Children Template by Parent TV - modX Revolution Plugin

defaultTemplateByParentTv

Plugin for modX Revolution

Set default template for children of a ressource

Author: Marc Loehe (boundaryfunctions)

Usage:

  1. Paste this as new plugin and connect it to system event 'OnDocFormRender'.
  2. Assign a new TV 'childDefaultTemplate' to each template, for which you want to define the default children template.
  3. Set the newly created TV to type List Box and its 'Input Option Values' to: @SELECT `templatename` AS `name`,`id` FROM `[[+PREFIX]]site_templates` This will fetch all available templates from the db.
  4. Have fun!

Changelog

2012-01-09

Fixed bug for compatibility with modX 2.2.0

2011-12-14

Initial release

<?php
/**
* =========================
* defaultTemplateByParentTv
* =========================
*
* Plugin for modX Revolution
* Set default template for children of a ressource
*
* Author:
* Marc Loehe (boundaryfunctions)
* marcloehe.de
*
*
* Usage:
*
* 1. Paste this as new plugin and connect it to system event
* 'OnDocFormRender'.
*
* 2. Assign a new TV 'childDefaultTemplate' to each template,
* for which you want to define the default children template.
*
* 3. Set the newly created TV to type List Box and its 'Input Option
* Values' to:
*
* @SELECT `templatename` AS `name`,`id` FROM `[[+PREFIX]]site_templates`
*
* This will fetch all available templates from the db.
*
* 4. Have fun!
*
*/
if ($modx->event->name == OnDocFormRender && $mode == modSystemEvent::MODE_NEW) {
if ($parentId = $_REQUEST['parent']) {
if ($parent = $modx->getObject('modResource', $parentId)) {
if ($childTemplate = $parent->getTVValue('childDefaultTemplate')) {
if (isset($modx->controller)) {
$modx->controller->setProperty('template', $childTemplate);
} else { // modX < 2.2.0
$_REQUEST['template'] = $childTemplate;
}
}
}
}
}
@janein
Copy link

janein commented May 3, 2013

just wanted to do the same and found this piece of code.
thanks for saving me the time! :)

@Bouwyn
Copy link

Bouwyn commented Jan 30, 2014

+1

This script is very much appreciated. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment