Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Add “active” class to Mage_Cms_Block_Widget_Page_Link
 
Sweet-Apple
Jr. Member
 
Avatar
Total Posts:  9
Joined:  2011-02-12
 

Very minor thing, but links created by Mage_Cms_Block_Widget_Page_Link should be able to highlight themselves by adding a class if the current url is the same as the link in the Widget_Link.

You could extend this to check it a link was a “parent” by matching fragments of the url as well.

Makes building list of links for CMS pages much easier from a presentational point of view, has pretty much zero overhead as well…

/**
* Add “active” class to link if it matches this url
* @return string
*/
public function getClass()
{
$currentUrl = Mage::helper(’core/url’)->getCurrentUrl();
if($currentUrl == $this->getHref() ) {
return “active”;
}
return;
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
jc_w2m
Jr. Member
 
Total Posts:  8
Joined:  2012-12-12
 

Hi, thanks for the great post! I am trying to apply this concept to top nav links added as a static block call from topmenu.phtml. I’ve tried adding your script to cms/block block.php and page.php. Working with CE 1.7. Thus far nothing breaks but the active state does not get added. Any thoughts would be greatly appreciated. Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top