Dynamically adjusting your page title in symfony

by Dave Dash 18Jul07

[tags]view, view.yml, symfony, reviewsby.us, title, seo[/tags]

A lot of the content on reviewsBy.us and other sites we make using symfony have dynamic content. We try to have our page titles reflect the content by prepending the name of the specific restaurant, document or menu item before the site name.

To do this we use a method called prependTitle. I define this in a file called myActions.class.php which almost all of my actions subclass in my projects. This way I can enhance all the actions simply by adjusting the common ancestor, myActions:

The page title isn't stored anywhere, so we have to put it in app.yml:

app:
  title: reviewsby.us

Voila!


Where am I?

This is a single entry in the weblog.

"Dynamically adjusting your page title in symfony" is filed under reviewsby.us and symfony. It was published in July 2007.

July 2007
M T W T F S S
« Jun   Aug »
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

Tags

&& && && && &&

need more help

If you found our tutorials and articles to be useful, but are still looking for more hands on help, consider hiring us. Find out more about how Spindrop can help you.

 

7 Responses to “Dynamically adjusting your page title in symfony”


  1. 1 akinas Posted July 28th, 2007 - 3:29 pm

    Great post. I also added the title from app.yml as a default title in view.yml like so:

    default: metas: title: ”

  2. 2 akinas Posted July 28th, 2007 - 3:32 pm

    Sorry! all the code got stripped. Should be:

    default:

    metas:

    title:        '<?php echo sfConfig::get('app_site_title'); ?>'
    
  3. 3 Joan Piedra Posted June 16th, 2009 - 9:44 pm

    Great idea, I tweaked it a little and wrapped it in a private function, it should be much easier to do a $this->setTitle(‘About Us’);

    Thanks for sharing.

    /** * Pre Executes all actions */ public function preExecute() { $d = sfConfig::get(‘app_title_delimiter’); $t = sfConfig::get(‘app_title’); $this->title = array(‘d’ => $d, ‘t’ => $t); $this->response = $this->getResponse(); }

    /** * Sets the Page Title * @param string $title The page title */ private function setTitle($title = ”) { $this->response->setTitle($title . $this->title['d'] . $this->title['t'], false); }

  4. 4 Joan Piedra Posted June 16th, 2009 - 9:45 pm

    Hey Dave,

    Great idea, I tweaked it a little and wrapped it in a private function, it should be much easier to do a $this->setTitle(‘About Us’);

    Thanks for sharing, Joan.

     /**
      * Pre Executes all actions
      */
      public function preExecute()
      {
        $d = sfConfig::get('app_title_delimiter');
        $t = sfConfig::get('app_title');
        $this->title = array('d' => $d, 't' => $t);
        $this->response = $this->getResponse();
      }
      
      /**
      * Sets the Page Title
      * @param string $title The page title
      */
      private function setTitle($title = '')
      {
        $this->response->setTitle($title . $this->title['d'] . $this->title['t'], false);
      }
    

Who's linking?

  1. 1 PHPDeveloper.org Trackback on Jul 20th, 2007
    "Dave Dash's Blog: Dynamically adjusting your page title in symfony... ... "
  2. 2 developercast.com » Dave Dash’s Blog: Dynamically adjusting your page title in symfony Pingback on Jul 20th, 2007
    "[...] Dash has posted a quick hit for symfony framework users - how to dynamically adjust your page title at ... "
  3. 3 rpsblog.com » A week of symfony #29 (16->22 July 2007) Pingback on Jul 23rd, 2007
    "[...] Dynamically adjusting your page title in symfony [...] "

Further Help

If you require more hands on assistance, we do offer affordable hands on support.

Leave a Reply


Comment guidelines: No spamming, no profanity, and no flaming. Inappropriate comments will be deleted outright.