0

Magento is still very much a learning curve for myself but I'm trying to steer away from so much of my hard-coded, procedural PHP and start following the Magento MVC. I've set myself the task of converting a singular .phtml file that I've created a best-sellers carousel for into an extension that follows the proper MVC. Here's my code/files:

app/code/local/Liam/Interested/etc/config.xml:

<?xml version="1.0"?>
<config>
<global>
    <modules>
        <liam_interested>
            <version>0.1.0</version>
        </liam_interested>
    </modules>
    <blocks>
        <interested>
            <rewrite>
                <interested>Liam_Interested_Block_Interested</interested>
            </rewrite>
        </interested>
    </blocks>

</global>
</config>

app/code/local/Liam/Interested/Block.php:

<?php
class Liam_Interested_Block_Interested extends Mage_Core_Block_Template
{
    // necessary methods
}
?>

app/etc/modules/Liam_Interested.xml:

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

app/design/frontend/custom/default/template/interested/interested.phtml:

<?php
echo 'test';
?>

Then, in my CMS - I'm adding:

{{block type="interested/interested" name="interested_interested" template="interested/interested.phtml"}}

This was based on following a guide online, but I still can't seem to get my head around it all!

4 Answers 4

0

You should change app/code/local/Liam/Interested/etc/config.xml file to:

<?xml version="1.0"?>
  <config>
      <modules>
         <liam_interested>
             <version>0.1.0</version>
         </liam_interested>
      </modules>
      <global>
         <blocks>
           <interested>
              <class>Liam_Interested_Block_Interested</class>
           </interested>
         </blocks>
      </global>
   </config>
1
  • I tried the above but my block still doesn't appear to be displaying my test content. Commented Nov 20, 2015 at 9:07
0

you have to define block class

<blocks>
        <interested>
                <class>Liam_Interested_Block</class>
        </interested>
    </blocks>

you can call block in xml

<block type="interested/interested" name="interested" template="interested/interested.phtml"/>
1
  • Didn't work for me I'm afraid. Struggling to work out why it won't work! Commented Nov 20, 2015 at 9:45
0

Follow bellow steps

Step : 1 app/etc/modules/Liam_Interested.xml:

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

Step : 2 app/code/local/Liam/Interested/etc/config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Liam_Interested>
            <version>0.1.0</version>
        </Liam_Interested>
    </modules>
    <global>
        <blocks>
            <interested>
                <class>Liam_Interested_Block_Interested</class>
            </interested>
        </blocks>
    </global>
</config>

Step : 3 app/code/local/Liam/Interested/Block.php:

<?php
class Liam_Interested_Block_Interested extends Mage_Core_Block_Template
{
    // necessary methods
}
?>

Step : 4 app/design/frontend/custom/default/template/interested/interested.phtml:

<?php echo 'test'; ?>

Step : 5 In CMS Page- :

{{block type="interested/interested" name="interested_interested" template="interested/interested.phtml"}}
6
  • Hi @Abdul - I tried all of the above but my block is still empty :( Commented Nov 20, 2015 at 9:07
  • if you try code in cms page then content display or not Code Is : {{block type="core/text_list" name="interested" as="interested" template="interested/interested.phtml"}} Commented Nov 20, 2015 at 9:32
  • Still nothing. Struggling to get my head around it and there doesn't seem to be that many tutorials on the Internet to achieve something as basic as this! Commented Nov 20, 2015 at 9:44
  • can you share screen shot to added cms page? Commented Nov 20, 2015 at 9:50
  • You are going wrong way in admin side cms page Commented Nov 20, 2015 at 9:51
0

You haven't required rewrite tag in your config.xml file.

Proper code :

<?xml version="1.0"?>
<config>
<global>
    <modules>
        <liam_interested>
            <version>0.1.0</version>
        </liam_interested>
    </modules>
    <blocks>
        <interested>
                <interested>Liam_Interested_Block</interested>
        </interested>
    </blocks>
</global>
</config>

Add in cms below code:

{{block type="interested/interested" name="interested_interested" template="interested/interested.phtml"}}
  1. Tag rewrite is useful when you have to change Core block functionality. You can check more info for overriding block from here. http://inchoo.net/magento/overriding-magento-blocks-models-helpers-and-controllers/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.