From 1a9f8df433e1b3de35593ec6a6f3f94df1b7591a Mon Sep 17 00:00:00 2001 From: Adrian Gonzales Jr Date: Thu, 5 Jul 2012 12:48:32 -0500 Subject: [PATCH] Added ability to build titles in a sequential manner. Successive calls to $this->template->title() are added together and then rendered. This is a config option that is turned off by default, to preserve backwards compatibility. --- config/template.php | 26 ++++++++++++++++++++++++++ libraries/Template.php | 20 ++++++++++++++++---- 2 files changed, 42 insertions(+), 4 deletions(-) mode change 100644 => 100755 config/template.php mode change 100644 => 100755 libraries/Template.php diff --git a/config/template.php b/config/template.php old mode 100644 new mode 100755 index 0e02ead..a3398a6 --- a/config/template.php +++ b/config/template.php @@ -43,6 +43,32 @@ $config['title_separator'] = ' | '; +/* +|-------------------------------------------------------------------------- +| Progressive Build Title +|-------------------------------------------------------------------------- +| +| Add successive calls to $this->template->title() to an array for combination later +| +| Default: FALSE +| +*/ + +$config['progressive_build_title'] = FALSE; + +/* +|-------------------------------------------------------------------------- +| Reverse Title Order +|-------------------------------------------------------------------------- +| +| If progressive build is turned on, do we reverse the title order before rendering? +| +| Default: TRUE +| +*/ + +$config['reverse_title_order'] = TRUE; + /* |-------------------------------------------------------------------------- | Layout diff --git a/libraries/Template.php b/libraries/Template.php old mode 100644 new mode 100755 index ca28ff1..404ae37 --- a/libraries/Template.php +++ b/libraries/Template.php @@ -24,7 +24,7 @@ class Template private $_layout_subdir = ''; // Layouts and partials will exist in views/layouts // but can be set to views/foo/layouts with a subdirectory - private $_title = ''; + private $_title = array(); private $_metadata = array(); private $_partials = array(); @@ -205,7 +205,10 @@ public function build($view, $data = array(), $return = FALSE) } // Output template variables to the template - $template['title'] = $this->_title; + if($this->_reverse_title_order){ + $this->_title = array_reverse($this->_title); + } + $template['title'] = implode($this->_title_separator, $this->_title); $template['breadcrumbs'] = $this->_breadcrumbs; $template['metadata'] = implode("\n\t\t", $this->_metadata); $template['partials'] = array(); @@ -281,7 +284,16 @@ public function title() if (func_num_args() >= 1) { $title_segments = func_get_args(); - $this->_title = implode($this->_title_separator, $title_segments); + + if($this->_progressive_build_title){ + if(count($title_segments) > 1){ + $this->_title = array_merge($this->_title, $title_segments); + } else { + $this->_title[] = $title_segments[0]; + } + } else { + $this->_title = $title_segments; + } } return $this; @@ -782,7 +794,7 @@ private function _guess_title() } // Glue the title pieces together using the title separator setting - $title = humanize(implode($this->_title_separator, $title_parts)); + $title[] = humanize(implode($this->_title_separator, $title_parts)); return $title; }