1

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?

2

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();
    }
}
  • Thanks a lot, this should work great as this is already an Extensions so should be easy to add in. In fact there is already 1-2 files in my app/code/local/Avenir/Avenirgallery/Block/ folder. A simple question... Form.php is there a reason for this name? Can it be any name? Just trying to learn more about the reasoning or if it doesn't matter? Thanks a bunch for the help in my journey to learn Magento – JasonDavis Dec 13 '13 at 13:37
  • Any name will be good but generally you will make the path and name of the Block class the same as the PHTML file. So [...]/templates/avenirgallery/form.phtml should have a block class file [Module]/Block/form.php Please don't use underscores in the classes filename since Magento will resolve this to slashes – Sander Mangel Dec 13 '13 at 13:41
  • Great thanks. I am having some issues getting this to work. After doing everything mentioned above, my page loads just fine but it will not change the title no matter what I do. I even set the title like this for testing $head->setTitle( 'My title' ); with no luck. I was then looking at my Extensions /etc/config.xml file and saw that there was an existing Block that is set in this config file so it got me thinking that perhaps I need to add this new Block to that file as well? – JasonDavis Dec 13 '13 at 14:05
  • <blocks> <avenirgallery> <class>Avenir_Avenirgallery_Block</class> </avenirgallery> <form> <class>Avenir_Avenirgallery_Block</class> </form> </blocks> – JasonDavis Dec 13 '13 at 14:06
  • Formatting is messed up but basically I copied the same way the other block was in this config file and did it for this one. Still no luck though on the desired result. Any ideas what I might be missing? Appreciate your time! – JasonDavis Dec 13 '13 at 14:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.