October 16, 2012

Magento Category with Category Images

Question by darshan.dodiya

I am facing one problem, So i am here to get Some solutions form you! I want to display category menu with category images near to each categories with in that menu.

So when i click on menu if that category contain sub-category it show the name of all those sub-categories with images near to it’s name like

example

parent1
  =>sub1 <Image of sub1 category>
  =>sub2 <Image of Sub2 category>
  =>sub3 <Image of sub3 category>

Same way i have parent2, parent3 etc., which contain sub-categories same way as i mention here.

So when i click on any parent category it will listed me sub-categories with it’s images!

If anybody having Idea about this then let me know how to do this.

Waiting for your response.

Thanks in advance.

Answer by Starx

You can get the image link using

$_imageUrl=$this->getCurrentCategory()->getImageUrl()

Follow this wiki from detailed walk-through.

September 5, 2012

How to set a default layout in Magento 1.5 using local.xml?

Question by Reed Richards

So I’ve done some layouts that I want to use and I was thinking that setting this in your local.xml file would fix this for every page. Like this

<default>
<reference name="root">
    <action method="setTemplate">
      <template>page/mytheme.phtml</template>
    </action>
</reference>
</default>

This however doesn’t do anything. Instead if I go

...<customer_account_forgotpassword>
  <reference name="root">
    <action method="setTemplate"><template>page/mytheme.phtml</template></action>
  </reference>
</customer_account_forgotpassword>  

<customer_account_confirmation>
  <reference name="root">
    <action method="setTemplate"><template>page/mytheme.phtml</template></action>
  </reference>
</customer_account_confirmation>...

and so on for every specific place it gets changed on those specific pages. Am I thinking wrong or this the only way to do it?

Answer by Alan Storm

The problem you’re (probably) running into is that something comes along later and sets the template for the root block again, overriding your change.

More recent versions of Magento (1.4somethingish) introduced a way to prevent this from happening. If you look in page.xml, you’ll see a handle like this

<page_one_column translate="label">
    <label>All One-Column Layout Pages</label>
    <reference name="root">
        <action method="setTemplate"><template>page/1column.phtml</template></action>
        <!-- Mark root page block that template is applied -->
        <action method="setIsHandle"><applied>1</applied></action>
    </reference>
</page_one_column>

If the page_one_column handle gets applied to your request, or you manually apply it with

<update handle="page_one_column" />

Magento will change the template and call the setIsHandle method on the block.

<action method="setIsHandle"><applied>1</applied></action>

There’s code in Magento that will look for the IsHandle property, and if it’s true, further calls to setTemplate will be ignored. (that’s over-simplifying things a bit, but is more or less true)

Try something like

<default>
    <reference name="root">
        <action method="setTemplate">
          <template>page/mytheme.phtml</template>
        </action>
        <action method="setIsHandle">
            <applied>1</applied>
        </action>       
    </reference>
</default>  

And see if that helps.

Keep in mind this is one of those grey areas where it’s not clear if third party developers are supposed to tread. Also, changing the template for all pages may have un-desirable effect on parts of the site that expect to be in a certain template.

Answer by Starx

Actually, you are the on the right track. You just didn’t specify the request on your local.xml. You should also include the request you are overriding.

Here is a example code of local.xml

<layout>
    <default>
    ....
    </default>

    <!-- Update Configuration for this request specially -->
    <customer_account_confirmation> 
      <reference name="root">
        <action method="setTemplate"><template>page/mytheme.phtml</template></action>
      </reference>
    </customer_account_confirmation>

</layout>

This much configuration is enough to do, what you need.

...

Please fill the form - I will response as fast as I can!