Jump to content

MarkupSimpleNavigation


Soma

Recommended Posts

Thanks guys, I really think it should be CSS, it was just I was having a hard time handling a select/option nav for some reason

Home

About

-- About This

-- About That

Blog

Work

-- This Work

-- That Work

Contact

Am sure I'll end up with it in CSS, was just wondering if there was an added class.

Link to comment
Share on other sites

I still have no idea what you want to target and how you imagine doing it... So I can't help.

I know what a child of a parent is, but it's not something I can get a hand on in a navigation, it's nothing specific or I just don't get it. :)

Maybe this is something you can use:

"list_field_class" => {template} p_{id}

or 

"list_field_class" => p_{name}
Link to comment
Share on other sites

Just wanted to let you all know, I updated the module to 1.1.9 , with another new hook method to manipulate or add your very special case classes that will get added to list_tpl's "%s". 

To use this, here a little example to make it clearer. I want to add a class to my page with id 1001. Ok here we go.

$nav = $modules->get("MarkupSimpleNavigation");

function hookGetListClass(HookEvent $event){
    $child = $event->arguments('page'); // current rendered page item (in naviation)
    $class = $event->arguments('class'); // the class string, may be empty or filled
    if($child->id == 1001){ // add your checks, use API or whatever... daytime...
        $event->return .= " yourclass"; // add your class names
    }
}

$nav->addHookAfter('getListClass', null, 'hookGetListClass');
echo $nav->render();

Added this to readme

  • Like 5
Link to comment
Share on other sites

Hi Soma,

first of all, thanks for this great module!

I get the following message displayed:

Notice: Undefined offset: 1 in C:\[...]\site\modules\MarkupSimpleNavigation.module on line 217
 

and this is one of my calls:

            <?php    
            $treeMenu = $modules->get("MarkupSimpleNavigation"); // load the module
            $rootPage = $page->parents->count == 1 ? $page : $page->parent;
            $options = array(
            'parent_class' => 'active',
            'current_class' => 'active',
            'max_levels' => 1,
            'outer_tpl' => ''
            );
            echo $treeMenu->render($options, null, $rootPage);
            ?>
 

any ideas what might cause this, or can I ignore the message?

cheers, j

Link to comment
Share on other sites

Hi!

I'm stuck again %)

I have structure something like that:

-Red

--Circle

--Square

-Blue

--Circle

--Triangle

...

I need to output "#parent-children" anchors (#red-circle, #red-square).

Is it possible to output parent name? I've tried {parent},but this is url to parent.

Or I need the Captain Hook to help?

Link to comment
Share on other sites

@k

Hi!

I'm stuck again %)

I have structure something like that:

-Red

--Circle

--Square

-Blue

--Circle

--Triangle

...

I need to output "#parent-children" anchors (#red-circle, #red-square).

Is it possible to output parent name? I've tried {parent},but this is url to parent.

Or I need the Captain Hook to help?

Without knowing further details/context, why not just build your own menu?

It can be as simple as

$menu = "<ul>";
foreach($pages->get("/sompath/")->children as $child) {
    $menu .= "<li><a href='#'>$child->title</a>";
    if($child->numChildren) {
        $menu .= "<ul>";
        foreach($child->children as $subchild) {
            $menu .= "<li><a href='#{$child->name}-{$subchild->name}'>$subchild->title</a></li>";
        }
        $menu .= "</ul>";
    }
    $menu .= "</li>";
}
$menu .= "</ul>";

echo $menu;

If you still want to go the module way, yes there you could make a hook to archive what you want. There's a couple examples in this thread, but there can't be enough I guess ;)

function hookTagsString($event){
    $child = $event->arguments("page");
    if($child->template == "form"){ // some check for template? as you like
        // now return your own link markup with $event->return
        $event->return = "<a href='#{$child->parent->name}-{$child->name}'>-$child->title</a>";
    }
}
$nav->addHookAfter("getTagsString", null,'hookTagsString');

// render the navigation
echo $nav->render(null, null, $pages->get("/somepath/"));
  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

A little tip for anyone wanting a drop-down arrow on submenu parents, like after 'About' below -

post-378-0-92208700-1372857353_thumb.png

just add something like this to your CSS.

li.has_children > a:after {
    content: "▼";
    font-size: 70%;
    padding-left: .5em;
    vertical-align: middle;
}
  • Like 5
Link to comment
Share on other sites

If I only want to show the top-level items, what would be the correct options?

I tried 

'max_levels' => 1,
'levels' => false,
'collapsed' => true, 

but I still get all items. Is this module "overkill" if I only want to list topmost pages? Should I be better just using a simple selector and foreach, to output such a simple nav-list?

Link to comment
Share on other sites

Well the correct option is, you're right:

$nav->render(array("max_levels" => 1));

"levels" area already false and only for classes. If you output only 1 level you don't need "collapsed" true.

Not sure what you mean with you get all items.

Link to comment
Share on other sites

OK, I'll try to rephrase it.

I have this in leftnav.inc:

$leftNav = $modules->get("MarkupSimpleNavigation");

$leftNavOptions = array(
    'max_levels' => 3,
    'collapsed' => true, // I guess this is the param that's not being executed correctly atm...
    'show_root' => false
);

echo $leftNav->render($leftNavOptions);

For simplicity's sake, let's say I have this basic 08-15 site structure:

- Company

- Products

- Downloads / Manuals

- News

Each of these main sections has sub-sections: max. 2 levels down.

Now, no matter if I'm at the root page of "products", or in a detail-page within products, the menu always outputs the entire tree. Like a sitemap, everything from A to Z. But that's not what I want. Shouldn't "collapsed = false" take care of that?

The idea is to have a basic HTML list that only displays the top-level hierarchy as links. But when I'm further down in level 1-2-3, it should recognize this... "ah, that's my home category, let's open up this navigation tree as well to show where we live".

Right now, all levels / sections are open all the time, at all levels, everywhere. "Collapsed" parameter true or false: doesn't change anything.

So e.g. if I'm visiting a product page (= 1 level down inside "products"), it should only render: 

- Company

- Products

  -- product A

  -- product B (= active)

  -- product C

- Downloads / Manuals

- News

But what the module actually does, is showing every single page, no matter how far up or down you currently are. Surely that was not the intention of the module?

So either I'm completely misunderstanding how this module is supposed to work, or it's some kind of bug. I'm sure I could visually hide the superflous elements via CSS, but I'd rather have the module not render them in the first place...

in a nutshell:

a) show only top-level links

+ b) but also show (nested) sub-levels if I am in inside this parent category, right down to the child (or grand-child document).

Link to comment
Share on other sites

Yes that's correct 'collapsed' does collapse all to the top level, except for those you'r on or in. It's only opening branches you're on.

'max_levels' does limit the levels rendered from the top level. 

So you example kinda illustrates this correct.

 Company

- Products

  -- product A

  -- product B (= active)

  -- product C

- Downloads / Manuals

- News

 

Also this 

 

 Company

- Products (= active)

  -- product A

  -- product B 

  -- product C

- Downloads / Manuals

- News

 

Or like this

 

 Company

- Products 

  -- product A

  -- product B 

  -- product C (= active)

     -- product C1

     -- product C2 

- Downloads / Manuals

- News

 

I don't know why it's not working for you, but I use it all the time, and I think quite a lot of others too.

Link to comment
Share on other sites

Actually, I'm beginning to believe it's a server issue. On another site / server it's working perfectly.

Could a multilingual site setup be a potential error source? (I wouldn't know why that would be the case, everything looks perfectly OK - just clutching at straws here...)

Link to comment
Share on other sites

If all else fails, I would strip my PW install down to the bare minimals (uninstall non-core modules; minus MSN of course ;)) or test in a vanilla PW install with only core modules and MSN installed and test from there to see if it works. Yeah, it is also good to test in different environments.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...