Tuesday, July 1, 2014

Re: Cakephp 2 - dynamic meta tags from beforeFilter

app/View/Layouts/default.ctp:
<meta name=“description” content="<?php echo empty($meta_description) ? ‘default meta description here’ : $meta_description ; ?>” />

and add this to your controllers actions or views:
$meta_description = $house[‘House’][‘meta_description'];
$this->set(compact(‘meta_description'));

Andras Kende

On Jul 1, 2014, at 2:33 AM, vbpupil <vbpupil@gmail.com> wrote:

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: