Magento Forum

   
Creating a Content Block, Documentation? 
 
Jon Edwards
Jr. Member
 
Total Posts:  29
Joined:  2008-10-10
 

From the numerous posts I’ve read, I know I’m not alone. I’m new to Magento, setting up my first site with magento, and naturally want to customize the look/feel. I’m having the hardest time doing what would normally be the most basic things. Moving elements around on a page! Basic HTML/CSS stuff. I’ve read the Magento User guide and the outdated Designer’s Guide. I’m just wondering if there is some documentation floating out there that I’m not aware of the someone could direct me to. I continue to spend countless hours searching through the forums, looking for answers. Isn’t there a manual? The user guide mostly addresses setting up the admin area (parts of that documentation are a little weak as well). But seriously guys, how is a person supposed to get anything done when there is no reference for the basic structure of magento’s file system.

For educational/experimental purposes, I want to create a test content block and insert it into the header block.  Based on several forum threads that I’ve read, I thought I pieced together the steps necessary to do this.  Can someone tell me where I’ve screwed up?

First - insert this line into page\html\header.phtml:  <?php echo $this->getChildHtml('testblock') ?>

<div class="header-top-container">
    <
div class="header-top">
        <
h1 id="logo"><a href="<?php echo $this->getUrl('') ?>"><img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" /></a></h1>
        <
class="no-display"><a href="#main"><strong><?php echo $this->__('Skip to Main Content'?> &raquo;</strong></a></p>
        
<?php echo $this->getChildHtml('topSearch'?>
        
<div class="quick-access">
            <
div class="shop-access">
                
<?php echo $this->getChildHtml('topLinks'?>
            
</div>
            
<?php echo $this->getWelcome() ?><br />
            
<?php echo $this->getChildHtml('store_language'?>
        
</div>
    </
div>
    
<?php echo $this->getChildHtml('testblock'?>
</div>
<?php echo $this->getChildHtml('topMenu'?>

Second - create the block in page.xml. Here’s what mine looks like:

<block type="page/html_header" name="header" as="header">
       <
block type="page/template_links" name="top.links" as="topLinks"/>
       <
block type="page/switch" name="store_language" as="store_language" template="page/switch/languages.phtml"/>
       <
block type="core/text_list" name="top.menu" as="topMenu"/>
       <
block type="page/html_testblock" name="testblock" as="testblock" template="page/html/testblock.phtml"/>
</
block>

A couple questions. What’s with the block “type” and where can I find more out about this? I read in one post that it refers to the location of the template for that block. Makes sense I guess, but then why the “template=” attribute? So on the line I added, I used a type of “page/html_testblock” which tells me that my template file needs to be called testblock.phtml and be located in page/html.  Am I getting this right? Why isn’t this explained somewhere?  Anyway this didn’t work so I threw in the “template=” attribute hoping that would help and no luck.

Finally, I create the template for this block called testblock.phtml, located in page/html and add one line to it:

<?php echo('TEST BLOCK'); ?>

Nothing....

What really frustrates me is that I want to understand magento so that I can customize it and fully take advantage of it’s features, but learning it by trial-and-error or by hunting through the pile of forum threads is far too time consuming and not effective. Am I missing something?!!! How can I learn this system.  I’d like to be able to look at some of the magento code and either understand what it’s doing, or know where I can look to figure out what it’s doing. Right now, I get on forum and search… For example, look at this code:

<block type="page/template_links" name="top.links" as="topLinks"/>

Can someone explain to me the basic concept of why this block uses name="top.links" and as="topLinks" ? I don’t get it.  I wish I didn’t have to ask someone to explain, I wish I could just read the manual and figure it out, but there is no manual!

Thanks for any help at all!

 
Magento Community Magento Community
Magento Community
Magento Community
 
deggertsen
Jr. Member
 
Avatar
Total Posts:  30
Joined:  2008-12-17
Utah
 

I’m pretty surprised nobody has responded to you on this. Today is my first day hacking away at Magento and for the most part I am quite impressed. However, the issues you raise here are the same issues I am running into. There is one question that you pose that I can answer though.

Can someone explain to me the basic concept of why this block uses name="top.links" and as="topLinks" ? I don’t get it.

You may have figured this out by now since it has been over a month since you posted but for once there needs to be some activity on a thread on the Magento Forum (I find that there seems to be very little admin activity).  Anyway, so the name="” attribute allows other xml files to reference to that block and actually add to it.  For example:

<reference name="root">
      <
action method="setTemplate"><template>page/2columns-right.phtml</template></action>
</
reference>
So the original block named “root” would appear elsewhere but this reference is actually adding a template to that block. Of course that could have been done originally with the template="” attribute but you get the idea. name="” allows you to name your block so that it can be referenced elsewhere.

The as="” attribute is what you use to assign a name that can be called in your template files.  For example:

<?php echo $this->getChildHtml('topLinks'?>
This is calling the block with the as="topLinks".

Hopefully that answers that question. The problem that I’m still trying to figure out now is the type="” attribute… It seems to me that the types are already set but there is no available list of the types. I would think that you should be able to create custom types in order to fully take advantage of the magento theme system, however on the designers guide when speaking of types it states “This is the identifier of the module class that defines the functionality of the block. This attribute must not be modified.” Seems silly to me that you cannot modify a blocks’ functionality or create a custom block function but maybe there is a good reason for this.  Obviously I’m still working to figure this out and if I do I’ll be sure to put it in this thread.  So it appears when you are creating your block in the page.xml file the problem is that you are using an undefined type, I don’t know why that doesn’t work but I would guess that is the problem.

I hope my comments here could help someone.  Please post if you know and understand the mystery of the type="” attribute.

 
Magento Community Magento Community
Magento Community
Magento Community
 
deggertsen
Jr. Member
 
Avatar
Total Posts:  30
Joined:  2008-12-17
Utah
 

I found some answers here:

http://www.magentocommerce.com/boards/viewthread/2690/

I’m still not satisfied though so I’ll keep looking…

 
Magento Community Magento Community
Magento Community
Magento Community
 
shamann
Jr. Member
 
Total Posts:  15
Joined:  2009-01-02
 

About attribute “type” in “block” tag.

I’m not sure. It seems that “type” refers to class, that renders the specified block.
For example:

<block type="page/template_links" name="top.links" as="topLinks"/>

“page/template_links” refers to class Mage_Page_Block_Template_Links which is located in app/code/core/Mage/Page/Template/Linkst.php
(Magento naming conventions is a separate topic. I will not discuss it here.)

/**
 * Simple links list block
 *
 * @category   Mage
 * @package    Mage_Core
 * @author      Magento Core Team <core@magentocommerce.com>
 */
class Mage_Page_Block_Template_Links extends Mage_Core_Block_Template
{

    
/**
     * All links
     *
     * @var array
     */
    
protected $_links = array();

    
/**
     * Set default template
     *
     */
    
protected function _construct()
    
{
        $this
->setTemplate('page/template/links.phtml');
    
}
...

So for test with testblock.phtml you can leave “type” attribute the same:

<block type="page/template_links" name="testblock" template="page/testblock.phtml" />

or even put core template renderer since you don’t need top links block functions
<block type="core/template" name="testblock"  template="testblock.phtml" />

In some cases you need extend that class to get custom functionality. For instance, you implemented your own class

class MyTest_MyPage_Block_MyLinks extends Mage_Page_Block_Template_Links
located in app/code/local/MyTest/Block/MyPage/MyLinks.php
and defined to override default class (it is done in Mytest/etc/config.xml). Then this block will be rendered by your class.

Creating a new module in your own namespace ("MyTest" in example) is still not clear for me.

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