Skip to content

Instantly share code, notes, and snippets.

@FuzzicalLogic
Created September 13, 2012 06:18
Show Gist options
  • Save FuzzicalLogic/3712291 to your computer and use it in GitHub Desktop.
Save FuzzicalLogic/3712291 to your computer and use it in GitHub Desktop.
MODx Revolution: Allows you to "nest" a MODx Revolution Template within another MODx Revolution Template. Requires the use of a Template Switcher plugin
<?php
// Requires an Template ID
if (empty($id))
return '';
else
{//Get the Template
$parent = $modx->getObject('modTemplate', $id);
// Must be a valid Template ID
if (empty($parent))
return '';
$parent = $parent->get('content');
// Adjust the Child Content by removing the call.
$child = $modx->getObject('modTemplate', $modx->resource->get('template'));
$child = $child->get('content');
$sansSnippet = preg_replace("/((?m)(!{0,1}\[\[!inheritTemplate\?{0,1}.{0,}\]\]))/", '', $child);
// Get the content
$adjusted = str_replace('[[*content]]', $sansSnippet, $parent);
$_REQUEST['inherited'] = $adjusted;
// Reset the already processed content
$output = $adjusted;
$modx->resource->_output = $output;
}
return $output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment