Home Ask Login Register

Developers Planet

Your answer is one click away!

Naga February 2016

From where, data comes to block in magento?

In base\default\template\customer/account/navigation.phtml the code is

<div class="block block-account">
<div class="block-title">
    <strong><span><?php echo $this->__('My Account'); ?></span></strong>
<div class="block-content">
        <?php $_links = $this->getLinks(); ?>
        <?php $_index = 1; ?>
        <?php $_count = count($_links); ?>
        <?php foreach ($_links as $_link): ?>
            <?php $_last = ($_index++ >= $_count); ?>
            <?php if ($this->isActive($_link)): ?>
                <li class="current<?php echo ($_last ? ' last' : '') ?>"><strong><?php echo $_link->getLabel() ?></strong></li>
            <?php else: ?>
                <li<?php echo ($_last ? ' class="last"' : '') ?>><a href="<?php echo $_link->getUrl() ?>"><?php echo $_link->getLabel() ?></a></li>
            <?php endif; ?>
        <?php endforeach; ?>

it display the following list :

account information

i know the block, but i want to know how the block receive this data and from where.if any link between block and model if its how. any one explain this overall flow.


b.enoit.be February 2016

They actually come from a class, which is something you can find back thanks to the block type.

Making a search on my Magento with the template (view) you state here customer/account/navigation.phtml will help you find the layout related to it.

And then you can find the block type.

So in customer.xml, you can find :

<block type="customer/account_navigation" name="customer_account_navigation" template="customer/account/navigation.phtml">

And this block type customer/account_navigation is actually the class Mage_Customer_Block_Account_Navigation that you can find in the file src/app/code/core/Mage/Customer/Block/Account/Navigation.php

To find back this class, there is a quite complicated game of xml handles and path to file mechanism that I already explained multiple time already, if you are curious about it : meaning and location of string inside Magento's Mage:getSingleton and Magento: call a custom block in CMS

The links there, as it looks that is what you are after, are, as you can see, a property of the class itself, that got filled in via :

public function addLink($name, $path, $label, $urlParams=array())
    $this->_links[$name] = new Varien_Object(array(
        'name' => $name,
        'path' => $path,
        'label' => $label,
        'url' => $this->getUrl($path, $urlParams),
    return $this;

And you can also see on some layout that they actually call this method to add links to that block, e.g. in review.xml

<reference name="customer_account_navigation">

Post Status

Asked in February 2016
Viewed 3,914 times
Voted 10
Answered 1 times


Leave an answer

Quote of the day: live life