Magento News

 

Can’t move top.links (topLinks) block in Magento

Hi,

I’m trying my very best to edit the Magento design the way they want you to (using a local.xml rather than editing the page.xml) but this system is so horrible and convoluted, it’s proving to be seriously tricky to do so.

The problem I have now is that I can’t seem to move the “top.links” block into another block in the header. At the moment in page.xml this block is within the header block. I’ve tried absolutely everything in my local.xml to get this to work, I’ve tried the following edits.

Remove top.links from header, add inside “Hud” block.

<layout version="0.1.0">

    <default>
        <!-- Here is where we edit the header block -->
        <reference name="header">
            <remove name="top.links" />
            <remove name="top.search" />
            <!-- This is the block that holds the HUD -->
            <block type="page/html" name="hud" as="hud" template="page/html/hud.phtml">
                <block type="page/template_links" name="top.links" as="topLinks" />
            </block>
        </reference>
    </default>

</layout>

alt text

Note that the links should be inside the brown box (this is the HUD block).

NOT removing the top.links block from header but adding to Hud block

<layout version="0.1.0">

    <default>
        <!-- Here is where we edit the header block -->
        <reference name="header">
            <remove name="top.search" />
            <!-- This is the block that holds the HUD -->
            <block type="page/html" name="hud" as="hud" template="page/html/hud.phtml">
                <block type="page/template_links" name="top.links" as="topLinks" />
            </block>
        </reference>
    </default>

</layout>

alt text

Created new Links template based on code of top.links, and referred to this in the HUD’s block as follows.

<layout version="0.1.0">

    <default>
        <!-- Here is where we edit the header block -->
        <reference name="header">
            <remove name="top.links" />
            <remove name="top.search" />
            <!-- This is the block that holds the HUD -->
            <block type="page/html" name="hud" as="hud" template="page/html/hud.phtml">
                <block type="page/template_links" name="hud.links" as="hudLinks" template="page/template/hudLinks.phtml"/>
            </block>
        </reference>
    </default>

</layout>

Below is hud.phtml

<!-- hud.phtml -->
<div id="hud">
    <h3>Welcome</h3>
    <?php echo $this->getChildHtml('hudLinks') ?>
    <?php echo $this->getChildHtml('top.search') ?>
</div>

This brings the most interesting results. I can see the template is found but nothing appears.

alt text

I really am clueless with this. Am I doing something completely wrong here? For what it’s worth, here is the code I’m using for hudLinks.phtml and the top.links template.

<?php $_links = $this->getLinks(); ?>
<?php if(count($_links)>0): ?>
<ul class="links"<?php if($this->getName()): ?> id="<?php echo $this->getName() ?>"<?php endif;?>>
    <?php foreach($_links as $_link): ?>
        <li<?php if($_link->getIsFirst()||$_link->getIsLast()): ?> class="<?php if($_link->getIsFirst()): ?>first<?php endif; ?><?php if($_link->getIsLast()): ?> last<?php endif; ?>"<?php endif; ?> <?php echo $_link->getLiParams() ?>><?php echo $_link->getBeforeText() ?><a href="<?php echo $_link->getUrl() ?>" title="<?php echo $_link->getTitle() ?>" <?php echo $_link->getAParams() ?>><?php echo $_link->getLabel() ?></a><?php echo $_link->getAfterText() ?></li>
    <?php endforeach; ?>
</ul>
<?php endif; ?>

Can’t move top.links (topLinks) block in Magento

Possibly Related Posts:


 

Leave a Reply