Last active
August 29, 2015 14:26
-
-
Save KINKCreative/db7acdf999ec33309500 to your computer and use it in GitHub Desktop.
PageSlugTemplate Controller Extension
This file contains 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 | |
// 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