setting page titles and meta tags in cakephp 1.3

David Jones

In the past when i have needed to have page titles and meta tags correctly setup for each page in a website i had often used methods like placing variables and setting them to the template in the app controller in a beforeFilter. Then if i needed a different meta tag on another page like contact for example i could go to the contact controller and and overwrite these variables. A great idea but didn’t work too well for the simple pages and the pages controller. Things never need to be this complicated it just seems to take a bit of time digging around cakephp to find what you need. I now use the following in cakephp 1.3, add the code below to any page template .ctp file and you can set its meta tag and page title. Its that easy!

    	$this->set("title_for_layout","your page title goes here");
    	$this->Html->meta('keywords', 'your keywords goes here', array('type' => 'keywords', 'inline' => false));
    	$this->Html->meta('description', 'your description goes here', array('type' => 'description', 'inline' => false));


Comments are currently closed