Jump to content

Recommended Posts

Posted

I'd like to add a dynamic parent class based on the page name. Is there a way of doing this at the moment or is it possible to add such a feature?

Something like:

'parent_class' => 'parent {name}'

or 

'active_parent' => true

This is such a great module and time saver! Thanks for creating it Soma!

Posted

Hey @mats, can you tell a little more what you want to do or better why, so I can think a little better? :)

Posted

Hi Soma! I have a news page with sections and sub sections, each section has it's own color which is inherited to it's subsections. When on a sub section i'd like to indicate both the current subsection and the parent section with the section color. Does this make any sense? :undecided:  

Posted

I might add a list field class option string, so you can add fields you want to each <li> item.

so you could add whatever classes and do:

'list_field_class' => '{template} p{id}',

and it would add this to every page list_tpl. And if left empty (default) it won't output.

I think then with this one can cover all aspects a basic navigation needs more or less.

  • Like 1
Posted

I just commited an update to 1.1.6

While editing the wiki documentation page it somehow was deleted after editing doh! So updated readme a little and copied that to the wiki.
 
 
`list_field_class` option (new in 1.1.6)
 
You can optionally define custom classes using a string that can contain tags for field names of pages.
For example:
 
'list_field_class' => '{template} p{id}', 
 
will add ' basic-page p1001' to each 'list_tpl' class string.
  • Like 1
Posted

Thanks for the update Soma. There seems to be a undefined variable named class in the code (line 238 if i remember correctly).  

I still would like to be able to set a class on the parent/s like the item_current_tpl, if possible. I think this would it a lot easier to style the navigation. I understand if you're not willing to add it since this kind of feature might have a bit limited use. 

Posted

Thanks mats for the heads up. I think It was late when doing this. Have to take a look a again at that $class variable. I should practice what I preach :D

As for the wish, I'm not sure what you mean because you can aleady define what you want:

parent_class : class for all active parents

has_children_class : class for parents that have children

now new

list_field_class: add classes like {name} to each item (which is what you need not?)

so a active parent of the current page will have

<li class="parent has_children about">...

I didn't just add this new feature to "parent_class" because adding the possibility to add {fieldname} to all items covers all needs and not just for parents.

  • Like 1
Posted

I dont really get what the problem is.

You have the current parent and the section.

list_field_class => 'p{id}'

Then in css

li.parent.p1001{..}

Or

li.parent.p1001 > a { ..}

To style active section item with parent id 1001

  • Like 1
Posted

You're right Soma, it's my css that's messed up and i'm stuck in the old way of styling the navigation. I just have to rethink it.

Thanks for all your help!

  • Like 1
Posted

If something I learned over the years, it's to watch your css for navigations ... :) as simple as possible pays out.

However since older browsers are left behind it good to move on.

I updated the Module to 1.1.7 to fix the warning. Thx for mention.

  • Like 1
Posted

Probably a simple thing to do but how would I go about having lowercase letters in the output?


Was thinking of using strtolower in the item_tpl but not sure how to approach it.

Thanks Soma.

Posted

Newbie question...

I donwnloaded this great module, but now run into some trouble, how can I do the following:

In order to reduce bounce rate I want to split up longer pages in sub pages.

I want to have the following structure for the pages that will be split into more pages

topic

- topic/page2

- topic/page3

- topic/page4

- topic/page5

then on each of all the pages above I want a clickable TOC just for this topic and its sub pages

How to do this so it is as much automated as possible?

Posted

Not exactly sure about the structure but you could try this:

If you have

/article/

/article/page1

/article/page2

/article/page3

Code on article page

$root = $page;
echo $nav->render(null, $page, $root); // $nav being instance of the module

And on the child pages

$root = $page->parent;
echo $nav->render(null, $page, $root);

$page being the current page and $root is from where it starts generating navigation.

Yu could also use the various options available to make adjustments, if not needed you can set it to "null" as in the example.

Posted

@Soma, thanks,

yes structure like you said is correct

/article/

/article/page1

/article/page2

And on each page (article and child I would like to see a snippet as output like the following:

<details class="pw-toc" open="open"><summary>In this article</summary>
<ol>
    <li><a class="active" href="http://mydomain.com/article/">How Processwire beats any CMS handsdown</a></li>
    <li><a href="http://mydomain.com/article/page2/">3 Mistakes You Should not make in choosing a CMS</a></li>
    <li><a href="http://mydomain.com/article/page3/">Can you do this with your current CMS</a></li>
</ol></details>

So if I use on the article page:

$root = $page;
echo $nav->render(null, $page, $root); // $nav being instance of the module

and on the child pages:

$root = $page->parent;
echo $nav->render(null, $page, $root);

What step is then further needed to produce the output like above?

Oh and just for anybody's information, stuff like this usually drops your bounce rate in most cases with 20-30% easily, so google clearly loves it, thanks!

Posted

Right with this structure it would look like this:

<details class="pw-toc" open="open">
    <summary>In this article</summary>
<?php
    $treeMenu = $modules->get("MarkupSimpleNavigation");
    $options = array(
        'max_levels' => 1,
        'current_class' => 'current',
        'outer_tpl' => '<ol>||</ol>',
        'show_root' => true
    );
    $root = $page->parents->count == 1 ? $page : $page->parent;
    echo $treeMenu->render($options, $page, $root);
?>
</details>
 

The root here is found by counting what level, and either take parent or page itself as the root.

--

You could also define root alternatively like maybe depending on the structure and templates:

$root = $page->parent->template == 'article' ? $page->parent : $page;
echo $treeMenu->render($options, $page, $root);

So saying if parent page template is 'article' take current page->parent as root, if not we take current page assuming it's the top 'article' page and not a child.

  • 2 weeks later...
Posted

Hi!

Read all thread, but can't solve my problem.

My structure:

Home

-- About

-- Something Else

-- Want it in menu1

----Subpage11

----Subpage12

---- ..more of them..

-- Want it in menu2

----Subpage21

----Subpage22

---- ..more of them2..

What is the easiest way to render only "Want it in menu 1|2" and their children?

I think of excluding all others pages, but pages can grow. How can I just point only 2 of pages to render?

Sorry for my English. Hope you understand what I mean.

upd:

If only be that you can specify multiple parents.

Posted

You can' specify multiple roots, but you can exclude children.

$options = array("selector"=>"id!=1003|1004");
echo $navTree->render($options);

So the pages with those id's wont be rendered.

Or you could add a checkbox custom field to the templates to only include them if checked from the navigation.

$options = array("selector"=>"show_in_menu=1");
echo $navTree->render($options);
  • Like 1
Posted

You can' specify multiple roots, but you can exclude children.

Thank you, Soma!

I'll try to exclude pages by template.

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...