Yii Framework Forum: Dynamic Meta Tag - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Dynamic Meta Tag Rate Topic: -----

#1 User is offline   Quark 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 22-May 13

Posted 23 May 2013 - 02:24 AM

I am doing a project in Yii framework now. i am concern about title tag and other meta tag which will be dynamic as well for SEO propose , The data for the tags will be fetched from database and displayed in the front-end.

What Should be my approach ?

Thanks in advance
0

#2 User is offline   yugene 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 504
  • Joined: 08-August 09

Posted 24 May 2013 - 01:38 AM

You may declare meta tags as main Controller properties and to set their values, for example at beforeRender() method.
Example:
Layout

        <meta name="keywords" content="<?php echo CHtml::encode($this->keywords)?>" />
        <meta name="description" content="<?php echo $this->description?>" />

Controller


    /**
 	* @var string meta tag keywords content 
 	*/
    public $keywords = '';

    /**
 	* @var string meta tag description content 
 	*/
    public $description = '';
    /**
 	* This method is invoked at the beginning of {@link render()}.
 	* @param string $view the view to be rendered
 	* @return boolean whether the view should be rendered.
 	*/
    protected function beforeRender($view)
    {
        list($keyword, $description) = Yii::app()->seoHelper->findMetaTags();
        $this->keywords = $keyword ? $keyword : Yii::app()->settings->get('meta', 'keywords');
        $this->description = $description ? $description : Yii::app()->settings->get('meta', 'description');

        return parent::beforeRender($view);
    }

For title there's a yii pageTitle. You may overwrite getPageTitle() with your own implementation.
0

#3 User is offline   jonnathan 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 23-May 13
  • Location:Vietnamese

Posted 24 May 2013 - 01:40 AM

I think you should creat new database table , and get this table to front-end .
Creat a table :
Seo
-META tag:
--meta title
--meta des
--meta tag
--meta robots
--meta property ( important for seo richsnippest)
...

-REL tag
rel="author"
rel="publiasher"
rel="canonical"
...
And then , use same code get in Yii !
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users