Skip to content

Instantly share code, notes, and snippets.

@Mark-H
Created September 28, 2012 11:30
Show Gist options
  • Save Mark-H/3799296 to your computer and use it in GitHub Desktop.
Save Mark-H/3799296 to your computer and use it in GitHub Desktop.
Change template for @datarecall #modx
<?php
$parent = 5;
$resourceWithChildrenTpl = 1;
$resourceWithoutChildrenTpl = 2;
$childs = $modx->getChildIds($parent);
foreach ($modx->getIterator('modResource',array('id:IN' => $childs)) as $resource) {
if ($resource->get('parent') == $parent) {
if ($resource->hasChildren() > 0) {
$resource->set('template', $resourceWithChildrenTpl);
$resource->save();
} else {
$resource->set('template', $resourceWithoutChildrenTpl);
$resource->save();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment