Skip to content

Instantly share code, notes, and snippets.

@argnist
Created November 26, 2013 03:26
Show Gist options
  • Save argnist/7653028 to your computer and use it in GitHub Desktop.
Save argnist/7653028 to your computer and use it in GitHub Desktop.
TemplatizerX - Дополнительно к кастомизации форм устанавливает шаблон в зависимости от шаблона родителя
<?php
switch ($modx->event->name) {
case 'OnDocFormRender':
if (!isset($_GET['template'])) {
$parent = isset($_GET['parent']) ? intval($_GET['parent']) : 0;
$templates = array(1 => 4, 6 => 13, 8 => 6, 5 => 6, 4 => 15, 7 => 11, 17 => array(16, 17));
if (isset($templates[$parent])) {
$template = $templates[$parent];
if (is_array($template)) {
$template = $template[0];
}
}
else {
$c = 1;
while ($parent != 0) {
$presource = $modx->getObject('modResource', $parent);
$parent = $presource->parent;
if (isset($templates[$parent]) && isset($templates[$parent][$c])) {
$template = $templates[$parent][$c];
}
$c++;
}
}
if (isset($template)) {
// $modx->regClientStartupScript("<script>location.href = location.href + '&template=' + " . $template . ";</script>");
$modx->controller->setProperty('template', $template);
}
}
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment