Jump to content

MarkupSimpleNavigation


Soma

Recommended Posts

  • 2 weeks later...
$features = $pages->find("bfd_events_people_id%=$page->id, sort=bfd_year");

That kind of selector could yield wrong results. If you are finding by ID, then you should really be using page references, not text fields. If you were searching for id "123" the selector above would also match "2123", "1234", "9912399", etc. That's why it could be problematic. If for some reason you needed to search this way (using text fields rather than page references) you'd be better off using the "~=" operator, which matches whole words and should provide more accurate results for that scenario. But this is a situation that really calls for page references (FieldtypePage). 

Link to comment
Share on other sites

I would like to have a navigation list of related pages (events) on a certain page.

find("template=bfd_events, bfd_events_people_id%=$page->id")

Where do I put the find option? In $rootPage = $pages->get("/events/"); or in options -> 'selector' => '',?

This module doesn't work like this. You can't specify "root" pages to build the menu using a find. It works from a "parent" its way down the tree. There's only a selector option to specify what pages would be included/excluded. For simple lists you're better off creating your own code which is very simple in PW.

Link to comment
Share on other sites

How exacly selector_field works ?
i made template called list in it there is a field (checkbox) called dont_show
if this checkbox is checked i dont want to show children of this template. how can i do this  ?

Ty




			
		
Link to comment
Share on other sites

How exacly selector_field works ?

i made template called list in it there is a field (checkbox) called dont_show

if this checkbox is checked i dont want to show children of this template. how can i do this  ?

selector_field is to define what field or property (runtime) you want to use to specify the selector.

Default is "nav_selector" so this would translate to:

$page->nav_selector = "yourselector"

a)

This can be a field on a page, create a text field named "nav_selector" and add it to you template. Now you can enter a selector on pages using this template and the module will take that if it's defined.

b)

Or you set it on the fly before you render the navigation. Then you don't need to have a text field "nav_selector" added to your templates at all. You just set the property with code.

This could be simply a little code you run to set the selector to those pages, in your case those that have the checkbox:

foreach($pages->find("dont_show=1") as $p) $p->nav_selector = "yourselector";

In your case I'm not sure what would be the best way to not render children of that page. Maybe something like this:

foreach($pages->find("dont_show=1") as $p) $p->nav_selector = "parent!=$p->id";

c)

Alternatively this could also work using the options "selector".

"selector" => "parent.dont_show=0";

but not sure really this is possible at all :)

  • Like 1
Link to comment
Share on other sites

any reason my

foreach($pages->find("dont_show=1") as $p) {
    $p->nav_selector = "parent!=$p->id";
}

shows only one result

parent!=1034 

where there should be id 1015 also??

c)


Alternatively this could also work using the options "selector".


"selector" => "parent.dont_show=0";

ye this is not working ;/

i can just choose template as a selector but this checkbox is so nice :P



Link to comment
Share on other sites

I don't really get what you trying to di anymore. Do you want to not show the page in nav that have checkbox checked or only its children? There is no thing like !children.subfield=value in PW, it's not a valid selector.

Link to comment
Share on other sites

i dont want to show a children of this template, and honestly it works.

here is a full code i use for my nav.
u can also view the page here: midven.avenueagency.eu
 

Page is still in building process

<?php

	$rootPage = $pages->get("/");
    $treeMenu = $modules->get("MarkupSimpleNavigation"); // load the module
    $options = array(
		'parent_class' => 'parent',
		'current_class' => 'current',
		'has_children_class' => 'has_children',
		'levels' => true,
		'levels_prefix' => 'level-',
		'max_levels' => 2,
		'firstlast' => false,
		'collapsed' => false,
		'show_root' => true,
		'selector' => '!children.dont_show=1',
		'outer_tpl' => '||',
		'inner_tpl' => '<ul>||</ul>',
		'list_tpl' => '<li%s>||</li>',
		'list_field_class' => '',
		'item_tpl' => '<a href="{url}"><span>{title}</span></a>',
		'item_current_tpl' => '<a href="{url}"><span>{title}</span></a>',
		'item_root_tpl' => '<a href="{url}"><span>{title}</span></a>',
		'xtemplates' => '',
		'xitem_tpl' => '<span>{title}</span>',
		'xitem_current_tpl' => '<span>{title}</span>'
		);
    function hookGetListClass(HookEvent $event){
	    $child = $event->arguments('page'); // current rendered child page
	    $class = $event->arguments('class'); // the class string already present

	    // any API check on that child
        $event->return .= " id_".$child->id; // add your custom class to the existing
	}
	$treeMenu->addHookAfter('getListClass', null, 'hookGetListClass');
?>

<nav id="main-nav">
	<div class="header"><a href="#side-nav" class="dropDown">Menu</a></div>
	<div class="wrap" data-target="#side-nav">
		<ul>
			<?php echo $treeMenu->render($options, $page, $rootPage); ?>
		</ul>
	</div>
</nav>

Link to comment
Share on other sites

I just update PW to dev version and it stopped working ;(

and im still with the problem. I used this method to not show children of thoes parents:

'selector' => '!parent=1034|1015',

but there is page id 1090 within 1015 which i need exceptionally show. is there some method to overrule selector ?
 

Link to comment
Share on other sites

Sorry I'm still not sure what you want to archive as everytime it's a little different. I'm a bit lost and can't say anything without knowing exactly and maybe try myself. I like to help you but can't. There seem to be multiple ways to archive what you want.

I'm reading your posts again and kinda lost what the current state is. As I showed you could add a selector per page using the find:

foreach($pages->find("dont_show=1") as $p) {
    $p->nav_selector = "parent!=$p->id";
}

This should work and I don't know why it does not in your case. But after all I haven't tried so I can't really say 100%.

Maybe you can tell me again if I understand correctly: You want to exclude children of a certain parent? Right? 

What I can say for sure is:

"!parent=1034|1015" just isn't a valid selector it would have to be "parent!=1034|1015".

But if you do this you can't overwrite it for a certain children to still show, as it will never get to it. Does that make sense? :)

Maybe you can draw me a picture?

Edit: corrected typo... oh dear.

Link to comment
Share on other sites

I pushed an update to 1.2.2, I seem to have forgot to commit earlier.

It fixes an issue with the new "selector_level[n]" option introduced previously. It wasn't working quite correctly and after lot of trying I found what was going on which was quite tricky. I'm not sure anyone was using this feature already so it might not make any difference, just wanted to make a note.

The additional selector option can be used to define selector for different levels like so:

"selector_level1" => "template!=news",

"selector_level2" => "id!=1033|1239",

...

Link to comment
Share on other sites

  • 3 weeks later...

Hello,

I have a litte problem in the understanding how the module is working.

When I just need a plain tree-menu this is the most easy way to accomplish the task. But I have two separate navigations that belong together.

For example:

 

First Navigation is a horizontal list with links of the 1st level.

 

Second Navigation is a vertical list with links of the 2nd+ level.

My problem is now, that I have no idea how I can build this with the module. How can I tell the second navigation to render just the 2nd level and more when the equivalent first item is active?!

Best regards and thanks,

Martin

Link to comment
Share on other sites

Martin, welcome to PW!

If I understand correctly, you want the horizontal menu to show children of the home page (plus maybe the home page itself), and the vertical menu to show children of the current page?

I would be inclined just to use some simple php - 

For the horizontal menu something like this, styled in CSS as a horizontal menu...

<ul>
<?php
$home = $pages->get('/');
echo "<li><a href='$home->url'>$home->title</a>";
foreach($home->children() as $child){
  echo "<li><a href='$child->url'>$child->title</a></li>";
}
?>
</ul>

And then for the vertical menu, something very similar...

<ul>
<?php
foreach($page->children() as $child){
  echo "<li><a href='$child->url'>$child->title</a></li>";
}
?>
</ul>

NB All written in browser, so untested, but should work  :)

Link to comment
Share on other sites

With MSN this could look like this:

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

// topnav
$current = $page->rootParent(); // current root page
echo $nav->render(array(
    'max_levels' => 1
  ), $current);

// subnav
echo $nav->render(array(
    'max_levels' => 1
  ), $page, $current);
 
  • Like 1
Link to comment
Share on other sites

Thanks DaveP and thanks Soma!

The MSN version is working fine! Thanks for that.

I built the plain PHP version by myself, but the problem was, that it changed navigation points when it gets deeper in hierarchy. Maybe I had another error in my code but it didn't worked the way I wanted it to... :)

Thanks for the fast response!

Link to comment
Share on other sites

  • 2 weeks later...

Thanks Soma for this example : https://gist.github.com/somatonic/6258081

Testing it on a multi language site with a bootstrap 3 menu, how can I hide the <b class="caret"></b> in the homepage link and make it href link work just for that parent? Note: I have another parent that will open the dropdown children's menu. 

 

After Soma's hooks setup to render the $navMarkup I have:

$navMarkup = $nav->render(
    array(
      'levels' => true,
      'show_root' => true,
      'selector'=>"limit=6, start=0",
      'max_levels' => 4,
      'current_class' => 'active',
      'has_children_class' => 'dropdown',
      'outer_tpl' => '<ul class="nav navbar-nav">||</ul>',
      'inner_tpl' => '<ul class="dropdown-menu">||</ul>',
        )
    );

Another thing, having this as a menu structure:

homepage

-about

-services

  -service one

  -service two

If I select the service one or two links in the services parent page, the children's class is "active" can I set the parent to "active" too?

thank you

Link to comment
Share on other sites

Nobody? :D

I don't have a testcase setup handy but I think you just need to stop home (id:1) from the entering the dropdown-toggle code, maybe:

// first level items need additional attr
if($item->numChildren(true) && count($item->parents) < 2 && !$item->id=1){
    $title = $item->get("title|name");
    $event->return = '<a href="#" class="dropdown-toggle" data-toggle="dropdown">' . $title . ' <b class="caret"></b></a>';
}
...

I'm not sure I understand what you mean by the "and make it href link work just for that parent?"

If I select the service one or two links in the services parent page, the children's class is "active" can I set the parent to "active" too?

Yes you can.

'parent_class' => 'active', // string (default 'parent') overwrite class name for current parent levels
  • Like 1
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
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By MarkE
      This fieldtype and inputfield bundle was built for storing measurement values within a field, rendering them in a variety of formats and converting them to other units or otherwise modifying them via the API.
      The API consists of a number of predefined functions, some of which include...
      render() for rendering the measurement object, valueAs() for converting the value to another unit value, convertTo() for converting the whole measurement object to different units, and add() and subtract() for for modifying the stored value by the value (converted as required) in another measurement. In the admin the inputfield includes a checkbox (which can be optionally disabled) for converting values on page save. For an example if a value was typed in as centimeters, the unit was changed to metres, and the page saved with this checkbox selected, said value would be automatically converted so that e.g. 170 cm becomes 1.7 m.

      A simple length field using Fieldtype Measurement and Inputfield Measurement.
      Combination units (e.g. feet and inches) are also supported.
      Please note that this module is 'proof of concept' at the moment - there are limited units available and quite a lot of code tidying to do. More units will be added shortly.
      See the GitHub at https://github.com/MetaTunes/FieldtypeMeasurement for full details and updates.
    • By tcnet
      File Manager for ProcessWire is a module to manager files and folders from the CMS backend. It supports creating, deleting, renaming, packing, unpacking, uploading, downloading and editing of files and folders. The integrated code editor ACE supports highlighting of all common programming languages.
      https://github.com/techcnet/ProcessFileManager

      Warning
      This module is probably the most powerful module. You might destroy your processwire installation if you don't exactly know what you doing. Be careful and use it at your own risk!
      ACE code editor
      This module uses ACE code editor available from: https://github.com/ajaxorg/ace

      Dragscroll
      This module uses the JavaScript dragscroll available from: http://github.com/asvd/dragscroll. Dragscroll adds the ability to drag the table horizontally with the mouse pointer.
      PHP File Manager
      This module uses a modified version of PHP File Manager available from: https://github.com/alexantr/filemanager
       
    • By tcnet
      This module implements the website live chat service from tawk.to. Actually the module doesn't have to do much. It just need to inserted a few lines of JavaScript just before the closing body tag </body> on each side. However, the module offers additional options to display the widget only on certain pages.
      Create an account
      Visit https://www.tawk.to and create an account. It's free! At some point you will reach a page where you can copy the required JavaScript-code.

      Open the module settings and paste the JavaScript-code into the field as shown below. Click "Submit" and that's all.

      Open the module settings
      The settings for this module are located int the menu Modules=>Configure=>LiveChatTawkTo.

       
    • By tcnet
      Session Viewer is a module for ProcessWire to list session files and display session data. This module is helpful to display the session data of a specific session or to kick out a logged in user by simply delete his session file. After installation the module is available in the Setup menu.

      The following conditions must be met for the module to work properly:
      Session files
      Session data must be stored in session files, which is the default way in ProcessWire. Sessions stored in the database are not supported by this module. The path to the directory where the session files are stored must be declared in the ProcessWire configuration which is by default: site/assets/sessions.
      Serialize handler
      In order to transform session data easier back to a PHP array, the session data is stored serialized. PHP offers a way to declare a custom serialize handler. This module supports only the default serialize handlers: php, php_binary and php_serialize. WDDX was dropped in PHP 7.4.0 and is therefore not supported by this module as well as any other custom serialize handler. Which serialize handler is actually used you can find out in the module configuration which is available under Modules=>Configure=>SessionViewer.

      Session data
      The session data can be displayed in two different ways. PHP's default output for arrays print_r() or by default for this module nice_r() offered on github: https://github.com/uuf6429/nice_r. There is a setting in the module configuration if someone prefers print_r(). Apart from the better handling and overview of the folded session data the output of nice_r() looks indeed nicer.

      Links
      ProcessWire module directory
      github.com
    • By Robin S
      Repeater Easy Sort
      Adds a compact "easy-sort" mode to Repeater and Repeater Matrix, making those fields easier to sort when there are a large number of items.
      The module also enhances Repeater Matrix by allowing a colour to be set for each matrix type. This colour is used in the item headers and in the "add new" links, to help visually distinguish different matrix types in the inputfield.
      Screencasts
      A Repeater field

      A Repeater Matrix field with custom header colours

      Easy-sort mode
      Each Repeater/Matrix item gets an double-arrow icon in the item header. Click this icon to enter easy-sort mode.
      While in easy-sort mode:
      The items will reduce in width so that more items can be shown on the screen at once. The minimum width is configurable in the field settings. Any items that were in an open state are collapsed, but when you exit easy-sort mode the previously open items will be reopened. You can drag an item left/right/up/down to sort it within the items. The item that you clicked the icon for is shown with a black background. This makes it easier to find the item you want to move in easy-sort mode. You can click an item header to open the item. An "Exit easy-sort mode" button appears at the bottom of the inputfield. Configuration
      In the field settings for Repeater and Repeater Matrix fields you can define a minimum width in pixels for items in easy-sort mode. While in easy-sort mode the items will be sized to neatly fill the available width on any screen size but will never be narrower than the width you set here.
      In the field settings for Repeater Matrix you can define a custom header colour for each matrix type using an HTML "color" type input. The default colour for this type of input is black, so when black is selected in the input it means that no custom colour will be applied to the header.
      Exclusions
      The easy-sort mode is only possible on Repeater/Matrix fields that do not use the "item depth" option.
       
      https://github.com/Toutouwai/RepeaterEasySort
      https://processwire.com/modules/repeater-easy-sort/
×
×
  • Create New...