Skip to content

Instantly share code, notes, and snippets.

@kinglozzer
Created July 6, 2015 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kinglozzer/1929c854e33a0fb92ab5 to your computer and use it in GitHub Desktop.
Save kinglozzer/1929c854e33a0fb92ab5 to your computer and use it in GitHub Desktop.
<% loop $Menu(1) %>
$RenderLayout
<% end_loop %>
<?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