Last active
December 17, 2015 03:59
-
-
Save jrotering/5547703 to your computer and use it in GitHub Desktop.
Fires on 'OnHandleRequest' event. Sets the template of new resources based on a property in the template of the parent resource.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (isset($_GET['a'])) { | |
$action = $modx->getObject('modAction', $_GET['a']); | |
if (is_object($action) && $action->get('controller') == 'resource/create') { | |
$parentID = isset($_REQUEST['parent']) ? (int) $_REQUEST['parent'] : 0; | |
if ($parent = $modx->getObject('modResource', $parentID)) { | |
$parentTpl = $parent->get('template'); | |
if ($parentTplObj = $modx->getObject('modTemplate', $parentTpl)) { | |
if ($props = $parentTplObj->getProperties()) { | |
$tpl = ($ff = $modx->fromJSON($props['childTemplate'])) ? $ff : null; | |
if ($tpl) { | |
$_GET['template'] = $tpl; | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I love this one! I use it on almost every project!