How to Dynamically Set a CMS Block’s Title

cmsPHPstatic-blockurl

We have a custom CMS type page that is added from the Category settings.
Created at /neon-signs/custom-neon-signs.html

Under that category setting, we set the URL Key and then also assign a CMS Block to show at that URL.

Now under our CMS Block settings we have…

{{block type="core/template" template="avenirgallery/custon_neon_sign_form.phtml"}}

This lets us build our CMS page from this .phtml file

Now we are facing a new challenge. In this page we will have a keyword like Custom, Personalized, etc

What we would like to do is replace this keyword everywhere in the page, based on the URL. So we can send traffic to different versions of the page and that keyword will be replaced.

Now I am able to do this with a URL like this with no problem…
/neon-signs/custom-neon-signs.html?keyword=Custom and then I can replace the keyword in the document using $_GET['keyword']

Now our issue is the Page Title. Right now our CMS Block has a title set like this
Custom Neon Signs

Since the Title is set in the Admin Panel for the CMS Block, there is no way for me to change it to be the value set in the URL /neon-signs/custom-neon-signs.html?keyword=Custom

So that is where my real question is… How can I Dynamically set the CMS Block's Title from code and have it over-ride the admin Panel setting for the CMS Block Title?

I hope there is a way?

Another bonus question would be, is there any way to have a more pretty URL to utilize our keyword in the URL? I am thinking, since the URL key is set in the Category setting, that it would be hard to change the URL's and I am better off just using my current method for now?

Thanks for any help in the matter. I really need to be able to dynamicly set the CMS Block Title from my .phtml file or some other way to have it take in the value from $_GET['keyword'] and apply it to part of the title?

Best Answer

You can change the page title from a block class. This would probably be the easiest in this case.

Create a custom extension and add a Block class by creating the file app/code/(community|local)/[Namespace]/Avenirgallery/Block/Form.php

Now set this class as the type in the tag discribed above {{block type="avenirgallery/form" template="avenirgallery/custon_neon_sign_form.phtml"}}

Now in the block class which would be [Namespace]_Avenirgallery_Block_Form

class [Namespace]_Avenirgallery_Block_Form extends Mage_Core_Block_Template
{
    protected function _prepareLayout()
    {
        $head = $this->getLayout()->getBlock('head');
        $head->setTitle( Mage::app()->getRequest()->getParam('keyword') );

        return parent::_prepareLayout();
    }
}