An 'always_expand' option for {bulletmenu...}

Talk about new features for CMSMS and modules.
Post Reply
geoffb

An 'always_expand' option for {bulletmenu...}

Post by geoffb »

This isn't so much a feature request as an "I just implemented this, here's how" that might be useful to other folks...

I'm doing a site that's primary goal is to sell products to punters. Products are in a  range of categories that are children of a top level page/menuitem called 'Products'. I want those categories to be always expanded on the left side 'bulletmenu' regardless of where in the site the visitor is browsing...

so I came up with an 'always_expanded' extension to the {bulletmenu} tag. My implementation goes something like this....

1) at about line 31 of function.bulletmenu.php, add the following:

Code: Select all

    $always_expand = isset($params['always_expand']) ? $params['always_expand'] : 0 ;
    $always_expand .= '.';

2) at about line 204 of function.bulletmenu.php, (immediately before the "$count++" line, add the following...

Code: Select all

if (substr($onecontent->Hierarchy(), 0, strlen($always_expand)) == $always_expand) {

    $remainder = substr($onecontent->Hierarchy(), (strlen($always_expand)));

    $log->debug('remainder: ' . $remainder);

    if (strpos($remainder, '.') == false) {

        $log->debug('Setting skipme to false (always_expand)');
        $skipme = false;
        continue;
    }
}


3) in your template, specify bulletmenu like this...

Code: Select all

  {bulletmenu always_expand="2"}


(where, for example, you want the children of content/menu item number '2' to be always expanded)


... and enjoy...

In a nutshell, it works by looking at the current level in the heirarchy of things that are set to be not displayed ('$skipme') and checks to see if they are an immediate child of the menuitem specified by always_expand. If they are, it resets skipme to false, and {bulletmenu ...} goes on to display the item.

I've made no attempt to trap errors, etc - it rates as quick hack, not necessarily production quality. This works ok for me, I don't promise it won't break for you  :D

Potential future improvement, allow more than one menuitem to be 'always_expand'ed. Only one is possible by this current method.

I hope this is useful to someone.

Geoff
(sonicGB on #cms)
geoffb

Re: An 'always_expand' option for {bulletmenu...}

Post by geoffb »

I suppose I should add that I made this mod on an installed 0.11.1 system. Affter just 24 hours, lots of improvements come to mind. An

Code: Select all

if ($always_expand) 
{ surrounding the whole thing, for example, might make the code marginally faster.

G
Post Reply

Return to “Feature ideas”