Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweaked Title Functionality #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions config/template.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 16 additions & 4 deletions libraries/Template.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down