Title, description and keywords in CakePHP 1.3

cake

We develop many of our web apps in CakePHP 1.3, which is a really great tool but sometimes suffers from sections missing in the manual. This is not so much a how-to, but more of a question as to whether there is a better way, perhaps built in to 1.3?

Setting a title is no problem, by outputting $title_for_layout in your layout and setting in your controller (or page view) with:

$this->set('title_for_layout', 'Your page title');


The approach for Meta details in the manual suggests:

echo $html->meta(
    'keywords',
    'enter any meta keyword here'
);
//Output <meta name="keywords" content="enter any meta keyword here"/>;
 
echo $html->meta(
    'description',
    'enter any meta description here'
   ); 
 
//Output <meta name="description" content="enter any meta description here"/>

Source: http://book.cakephp.org/view/1438/meta

We take time over our SEO and this doesn’t seem as ideal as the title, as the description should be unique and descriptive as per the title. We looked to use the same basis as title and have now added:

if(isset($description_for_layout)){ echo "<meta name='description' content='".$description_for_layout."' />"; }
if(isset($keywords_for_layout)){ echo "<meta name='keywords' content='".$keywords_for_layout."' />"; }

Allowing for easy use with the title in a little ‘SEO block’, to be used in either a controller or view (e.g. for pages):

$this->set('title_for_layout', 'My page title');
$this->set('description_for_layout', 'My page description');
$this->set('keywords_for_layout', 'Keyword 1, Keyword 2, Keyword 3');

If you know of a better ‘CAKE’ way, then do please let us know.

  • http://www.ethno-urban.fr Ethno

    Exactly what I searched!
    Perhaps you can add an else with a default meta description and keywords…

    Have a good day!

Currently untagged