Skip to content

Commit

Permalink
refactor code to make use of renderWith method... best practice
Browse files Browse the repository at this point in the history
  • Loading branch information
Darren-Lee Joseph authored and Darren-Lee Joseph committed Oct 17, 2015
1 parent 7215891 commit a6a1016
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions code/UtilityPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,13 @@ public function getCMSFields() {
*/
public static function get_top_level_templates() {

$ss_templates_array = array(); //initialise empty array
$ss_templates_array = array();
$current_theme_path = THEMES_PATH . '/' . Config::inst()->get('SSViewer', 'theme');

//theme directories to search
$search_dir_array = array(
MAINTENANCE_MODE_PATH .'/templates',
$current_theme_path .'/templates'
//$current_theme_path .'/templates/Layout' //we only want top level templates
);

foreach($search_dir_array as $directory) {
Expand Down Expand Up @@ -170,12 +169,17 @@ public static function get_top_level_templates() {
*/
class UtilityPage_Controller extends Page_Controller {

public $templates; //required for template overrides
private static $url_handlers = array(
'*' => 'index'
);

private static $allowed_actions = array();

public function init() {
parent::init();
}

public function index() {

$config = $this->SiteConfig();

Expand All @@ -184,10 +188,12 @@ public function init() {
return $this->redirect(BASE_URL); //redirect to home page
}

$this->response->setStatusCode($this->ErrorCode);

if($this->dataRecord->RenderingTemplate) {
$this->templates['index'] = array($this->dataRecord->RenderingTemplate, 'Page');
return $this->renderWith(array($this->dataRecord->RenderingTemplate, 'Page'));
}

$this->response->setStatusCode($this->ErrorCode);
return array();
}
}

0 comments on commit a6a1016

Please sign in to comment.