0
votes

I have created a .phtml file at /app/design/frontend/mytemplate/default/template/page/html/footer.cat.links.phtml

which at the moment simply contains 1 html div, with some text in it.

I'm trying to add this to the footer but I've not toyed around with the layout xml before.

So, I opened up /app/design/frontend/mytemplate/default/layout/page.xml, and tried adding:

<block type="catalog/navigation" name="footer.cat.links" as="footerCatLinks" template="page/html/footer.cat.links.phtml" />

(Type is "catalog/navigation" as I intend to get this to work: http://www.magentocommerce.com/wiki/4_-_themes_and_template_customization/catalog/getting_and_using_categories_and_subcategories)

I put it just inside the footer block like this:

<block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml"><my block here></block>

Then in footer.phtml, I have tried to call the new block with:

<?php $this->getChildHtml('footerCatLinks') ?>

I've refreshed the cache etc. but it doesn't add the html div in footer.cat.links.phtml when I view in browser.

I finally thought I was getting my head around Magento a bit, but from my understanding of the documentation this should work! How wrong am I?

1
What layout handle surrounds your block tag in page.xml?Alan Storm

1 Answers

6
votes

In Magento's layout xml the block "type" attribute dictates to the system what type of block it should try to load, so specifying type="catalog/navigation" instructs Magento that it needs to load Mage_Catalog_Block_Navigation.

Unless you have written your own block class - which is totally unnecessary in this case - you should use a block of type core/template instead. You can then proceed to load your category list by leveraging the category model (Mage::getModel('catalog/category');) directly in your .phtml file.

I generally like to use the same value for both name="" and as="", so to add your block to the footer for all pages I would use the following xml within the <default> layout section:

<reference name="footer">
    <block type="core/template" template="page/html/footer.cat.links.phtml" name="footer_cat_links" as="footer_cat_links" />
</reference>

Be sure to refresh your layout xml cache if you have caching enabled (System>Cache Management).

Note that you do not need to call $this->getChildHtml('footer_cat_links'); as the footer block should already contain $this->getChildHtml(); which will iterate over all child items assigned to the footer block.