From c60b276d2669f54bc59c499556649912463fa918 Mon Sep 17 00:00:00 2001 From: Jeremy Bush Date: Wed, 4 Aug 2010 14:14:19 -0500 Subject: [PATCH] Adding new View_Layout class, to replace the layout controller completely. --- README.markdown | 7 ++++++ classes/controller/layout.php | 43 ----------------------------------- classes/view/layout.php | 25 ++++++++++++++++---- templates/layout.mustache | 2 +- 4 files changed, 29 insertions(+), 48 deletions(-) delete mode 100644 classes/controller/layout.php diff --git a/README.markdown b/README.markdown index 985b401..6c6b807 100644 --- a/README.markdown +++ b/README.markdown @@ -186,6 +186,13 @@ Controller: } } // End Welcome +Using the View_Layout class +--- + +KOstache comes with a View_Layout class instead of a template controller. This allows your layouts to be more OOP and self contained, and they do not rely on your controllers so much. + +To use it, have your view extend the View_Layout class. You can then specify your own layout file by placing it in templates/layout.mustache. At a minimum, it needs to have a {{>body}} partial defined in it. + For specific usage and documentation, see: [PHP Mustache](http://github.com/bobthecow/mustache.php) diff --git a/classes/controller/layout.php b/classes/controller/layout.php deleted file mode 100644 index 350aa3b..0000000 --- a/classes/controller/layout.php +++ /dev/null @@ -1,43 +0,0 @@ -auto_render === TRUE) - { - // Load the layout - $view_class = 'View_'.$this->template; - $this->template = new $view_class; - } - - return parent::before(); - } - - /** - * Assigns the layout [View] as the request response. - */ - public function after() - { - if ($this->auto_render === TRUE) - { - $this->request->response = $this->template; - } - - return parent::after(); - } - -} // End Controller_Layout diff --git a/classes/view/layout.php b/classes/view/layout.php index 6c6ce09..dad6e88 100644 --- a/classes/view/layout.php +++ b/classes/view/layout.php @@ -1,6 +1,8 @@ _partials+=array( + 'body' => file_get_contents(Kohana::find_file('templates', $view_location, 'mustache')) + ); + + // Make the layout view the child class's template + $this->_template = file_get_contents(Kohana::find_file('templates', self::LAYOUT, 'mustache')); + + return parent::render($template, $view, $partials); + } + +} // End View_Layout \ No newline at end of file diff --git a/templates/layout.mustache b/templates/layout.mustache index 8d5de27..1a3d9fa 100644 --- a/templates/layout.mustache +++ b/templates/layout.mustache @@ -6,6 +6,6 @@

{{title}}

-

{{content}}

+

{{>body}}

\ No newline at end of file