Tuesday, July 1, 2014

Cakephp 2 - dynamic meta tags from beforeFilter

Hi Guys

Im trying to generate dynamic facebook meta tags for a share button

eg:

	<meta property="og:description" content="description text"/>  	<meta property="og:image" content="http://www.myurl.co.uk/img/icon.png"/>

im guessing that the best way to do this is by setting the values in the beforeFilter of my controller.

ie controller:

    public function beforeFilter(){
        $desc = 'test description text';
        $this->set('meta_desc', $desc );

    }

and then calling it in my layout file.

<!DOCTYPE html>

<?php
    if(!isset($meta_desc)) {
        $meta_desc = 'House For Sale';
    }
?>

which works for static text, but how can i get database values which are used to build the body of the page?

I hope this makes sense


Thanks

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: