Skip to content

Instantly share code, notes, and snippets.

@KINKCreative
Last active August 29, 2015 14:26
Show Gist options
  • Save KINKCreative/db7acdf999ec33309500 to your computer and use it in GitHub Desktop.
Save KINKCreative/db7acdf999ec33309500 to your computer and use it in GitHub Desktop.
PageSlugTemplate Controller Extension
<?php
// This extension allows for URLSegment-based layouts
// Inspired by how Wordpress handles templates
// e.g. For mysite.com/testurl
// it gives priority to the Page-testurl.ss template if it exists
// Code submitted by <Klemen Novak/klemen@designcollective.io>
class PageSlugTemplate_ControllerExtension extends Extension {
public function onAfterInit() {
$action = $this->owner->request->param('Action');
if(!$action) $action = 'index';
$templateName = "Page-" . $this->owner->URLSegment;
if(SSViewer::hasTemplate($templateName)) {
$this->owner->templates[$action] = array($templateName, 'Page');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment