Magento Forum

   
How do I put a PHP script on the homepage? 
 
Brady
Guru
 
Avatar
Total Posts:  330
Joined:  2007-09-10
Orange County, CA
 

I have the homepage all laid out in the Admin > CMS.  The homepage includes a PHP RSS viewer.  But when I got to the live site, it just displays text, and does not run the PHP script.

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

You can not inculde PHP code in CMS pages.

You’ll need to create a block (ex. Mage_Brady_Block_Rss) with this functionality implemented in toHtml() method and call it from CMS page as:
{{block type="brady/rss"}}

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brady
Guru
 
Avatar
Total Posts:  330
Joined:  2007-09-10
Orange County, CA
 

Hi Moshe,

Ok, I created a new file: app > code > core > Mage > Brady > Block > Rss.php which includes my PHP RSS Parser and placed the {{block type="brady/rss"}} code in my homepage code.

When I visit the homepage, the RSS does parse, but the rest of the homepage does now show up, and I receive the error:

Fatal error: Class 'Mage_Brady_Block_Rss' not found in /homepages/2/d212266666/htdocs/store/app/code/core/Mage/Core/Model/Layout.php on line 309

How do I fix that?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

Try this shortcut to test your PHP code, but note that to share this functionality you will need to create a module, with example as in wiki article about creation of payment module:

create file app/code/local/Mage/Brady/Block/Rss.php:

<?php

class Mage_Brady_Block_Rss extends Mage_Core_Block_Abstract
{
  
public function toHtml()
  
{
  
// create your html here and assign to $html variable
    
return $html;
  
}
}

Put this in your local.xml:

<!-- add this -->
    <
blocks>
      <
brady>
        <class>
Mage_Brady_Block</class>
      </
brady>
    </
blocks>
<!-- 
right before the end -->

  </global>
</
config>

Now you can use it in CMS pages as {{block type="brady/rss"}}

Again, please note that this is not correct way of creating a module, but as a test for custom block should work.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brady
Guru
 
Avatar
Total Posts:  330
Joined:  2007-09-10
Orange County, CA
 

Thanks Moshe.  I’m headed out for the evening but will try that later tonight or tomorrow morning. Will let you know!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top