Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Can’t get my Custom block to show in cms pages. 
 
Webunity
Member
 
Total Posts:  55
Joined:  2008-06-17
 

Okay i followed the steps on:
http://www.exploremagento.com/magento/using-php-code-on-a-cms-page-custom-blockmodule.php

I made the following files/with the following content

/app/etc/Webunity_all.xml

<?xml version="1.0"?>
<config>
    <
modules>
        <
Webunity_CMS>
            <
active>true</active>
            <
codePool>local</codePool>
        </
Webunity_CMS>
    </
modules>
</
config>

/app/code/local/Webunity/CMS/etc/config.xml

<?xml version="1.0"?>
<config>
<
modules>
<
Webunity_CMS>
<
version>0.1.0</version>
</
Webunity_CMS>
</
modules>
<global>
<
blocks>
<
webunity_cms>
<class>
Webunity_CMS_Block</class>
</
webunity_cms>
</
blocks>
</global>
</
config>

/app/code/local/Webunity/CMS/Block/ListBrands.php

<?php
class Webunity_CMS_Block_ListBrands extends Mage_Core_Block_Template
{
protected function _toHtml() {
$html 
parent::_toHtml();
$html.= 'This is a test';
return 
$html;
}
}

Then, i tried to call the CMS block like this:

{{block type="webunity_cms/listbrands"}}

But it does not show, even though i have caching off. What did i do wrong?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Periculi
Sr. Member
 
Total Posts:  249
Joined:  2009-02-03
 

Does your Block class need a __construct method?

I got a block to show up that way, but also used a template declaration in the {{block type="” template=""}}

 
Magento Community Magento Community
Magento Community
Magento Community
 
LindyKyaw
Sr. Member
 
Avatar
Total Posts:  138
Joined:  2008-01-02
Los Angeles
 

You need to use as (the capital letter for “B") since you called your class name as Webunity_CMS_Block_ListBrands.:

{{block type="webunity_cms/listBrands"}}

If you change your class name to Webunity_CMS_Block_Listbrands and rename your file into Listbrands.php, you can use the block as

{{block type="webunity_cms/listbrands"}}

If you take a look at app/code/core/Mage/Core/functions.php, we have __autoload method as

function __autoload($class)
{    
     $classFile 
uc_words($classDIRECTORY_SEPARATOR).'.php'
    include(
$classFile);
}

function uc_words($str$destSep='_'$srcSep='_')
{
    
return str_replace(' '$destSepucwords(str_replace($srcSep' '$str)));
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
Webunity
Member
 
Total Posts:  55
Joined:  2008-06-17
 

Thanx, this worked for me wink

 
Magento Community Magento Community
Magento Community
Magento Community
 
yuenyiupang
Jr. Member
 
Total Posts:  8
Joined:  2009-04-15
 

I have a same case , but i dont think the answer can solve my solution

i have a custom module which has the function as a forum

it has one controller with 2 action, index and add

and 2 blocks

and 2 templates

let say my module name is Forum

mypackage is MYcompany

default block name = Blockname.php

when i type http://www.mycart.com/forum

i can see some data

when i go to cms and create page, named Forums and ID Forums

and type
{{block type=’mycompany_forum/blockname” template="forum/index.phtml"}}

when i type http://www.mycart.com/Forums

i got nth

can anyone help to solve this problem???

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