Question

I have a category page called "team", which is nested in my menu structure.

How can I link to that page and url, from within a phtml page elsewhere? I am of course wanting it to be dynamic.

For images I've been using:

echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).

but I am currently braindead on how to do that with category pages.

(side note - I use multi-language, multi-views.)

Was it helpful?

Solution

You can create a link with current web URL by using

Mage_Core_Model_Store::URL_TYPE_WEB

i.e.

<a href="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).'company/team.html'?>">meet the complete team</a>

Then to make it internationalized ... 1 approach that comes to mind (and after consulting with google for something better) ... is to add translation.

If you are using a your own module for the above changes, you can:

  1. for example for a Italian storeview, create an YourNamespace_YourModule.csv at app/locale/it_IT/
  2. in that /it_IT/YourNamespace_YourModule.csv add the following lines

    "company/team","società/squadra"

    where ""società/squadra" are the names of the category/sub in Italian and

    "meet the complete team","the link text in Italiano goes here"

  3. after that modify the link to be

    <?php $my_helper = Mage::getHelper('yournamespace_yourmodule')?>
    <a href="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB).$my_helper->__('company/team')'.html'?>"><?php echo $my_helper->__('meet the complete team')</a>
    

    where in Mage::getHelper('yournamespace_yourmodule') 'yournamespace_yourmodule' should be the XML path to your Helper, as defined in your config.xml

  4. repeat for any language/storeview you might need

If you are not using your own helper, you can add the above translations to a core module translation file and call the respective core module Helper in the link.

Hopefully, someone of the Magento gurus could provide a more canonical approach to the task, if not, the outlined approach seems reasonable enough to me.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top