Reputation: 2960
I'm setting individual page titles in my controllers' actions using:
$this->set( 'title_for_layout', 'Some Title' );
What I want to achieve is append a site title string to all these titles before rendering, i.e. say, "Some Title :: Site Name".
The easiest way out would be to add this string manually to each point where the page title is set - but that's like the brute force way.
What I tried was to override the beforeRender()
method of each controller and add this statement:
$this->set( 'title_for_layout', $this->title_for_layout . ' » ' . Configure::read( 'Site.title' ) );
I thought this would append the site's title to the page title for each action - but what I get instead is:
Notice (8): Undefined variable: SomeController::title_for_layout [APP\controllers\some_controller.php, line xx]
It seems like the title_for_layout
(set in individual actions in the controller) hasn't been set yet - which is throwing up this error.
My question is, where & How can I append the site title globally to all page titles - if not in this way?
Thanks, m^e
Upvotes: 2
Views: 823
Reputation: 21973
If you really want to append the same string to all your page titles, put it in the layout after $title_for_layout.
Upvotes: 1