0

I am trying to create a block containing a method callable on my template

I believe i doing something wrong with capital letters or declaration conventions in my xml files. I did not manage to declare properly my block in the layout file.

can anyone help ?

local/Maticode/WebLog/etc/config.xml :

        <?xml version="1.0"?>
         <config>
           <modules>
              <Maticode_WebLog>
                 <version>
                 0.1.0
                 </version>
              </Maticode_WebLog>
           </modules>


           <frontend>

               <routers>           
                   <weblog>
                      <use>standard</use>
                      <args>
                       <module>Maticode_WebLog</module>
                      <frontName>weblog</frontName>
                      </args>
                 </weblog>
               </routers>

                 <layout>
         <updates>
                <weblog>
                     <file>webloglayout.xml</file>
                </weblog>
                 </updates>
         </layout>



                </frontend>   

                     <global>
                          <blocks>
                             <weblog>
                                <class>Maticode_WebLog_Block</class>
                            </weblog>
                          </blocks>
                       </global>

                 </config>

local/Maticode/WebLog/Block/monblock.php:

         <?php
           class Maticode_WebLog_Block_Monblock extends Mage_Core_Block_Template
          {
             public function methodblock()
             {
               return 'informations de mon block !!';
             }
           }

design/frontend/base/default/layout/webloglayout.xml:

         <layout version="0.1.0">
           <weblog_index_index>
             <reference name="root">
               <!--http://localhost/magento/weblog/ outputs : 'here'-->

               <!--  <block type="page/html" name="root" output="toHtml" template="weblog.phtml" />-->

               <!--this does not display the template  -->
         <block type="weblog/monblock" name="afficher_monbloc" template="weblog.phtml" />
             </reference>
           </weblog_index_index>
         </layout> 

design/frontend/base/default/template/weblog.phtml:

        <?php
      echo 'here';     
      echo $this->methodblock();
         ?>

1 Answer 1

1

You need to register Block in config.xml file as follows (inside config tag)

<global>
    <blocks>
        <weblog>
            <class>Maticode_WebLog_Block</class>
        </weblog>
    </blocks>
</global>

And "local/Maticode/WebLog/Block/monblock.php" this file should be "local/Maticode/WebLog/Block/Monblock.php"

and layout should be

<weblog_index_index>
    <reference name="content">
        <block type="weblog/monblock" name="afficher_monbloc" template="weblog.phtml" />
    </reference>
</weblog_index_index>
1
  • monblock.php works also!name="content" instead of name="root" solved the problem. i don't know why and how does this reference attributes work...
    – Matoeil
    May 6, 2014 at 15:20

Your Answer

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

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