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();
 ?>
asked May 6, 2014 at 14:24

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>
answered May 6, 2014 at 14:47
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... Commented May 6, 2014 at 15:20

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.