-
-
Save dljoseph/ed5414c0a9a5a59fafec to your computer and use it in GitHub Desktop.
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
<% loop $Menu(1) %> | |
$RenderLayout | |
<% end_loop %> |
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 | |
class Page extends SiteTree { | |
/** | |
* Mimics the bevahiour of $Layout in templates | |
* @return HTMLText | |
*/ | |
public function RenderLayout() { | |
$template = $this->findLayout(); | |
$subtemplateViewer = new SSViewer($template); | |
$subtemplateViewer->includeRequirements(false); | |
return $subtemplateViewer->process($this); | |
} | |
/** | |
* Find the appropriate "$Layout" template for this class | |
* @throws Exception | |
* @return string | |
*/ | |
protected function findLayout() { | |
$theme = Config::inst()->get('SSViewer', 'theme'); | |
$templateList = array(); | |
$parentClass = $this->class; | |
while($parentClass !== 'SiteTree') { | |
$templateList[] = $parentClass; | |
$parentClass = get_parent_class($parentClass); | |
} | |
$templates = SS_TemplateLoader::instance()->findTemplates($templateList, $theme); | |
if( ! isset($templates['Layout'])) { | |
throw new Exception('No layout found for class: ' . get_class($this)); | |
} | |
return $templates['Layout']; | |
} | |
} | |
class Page_Controller extends ContentController { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment