Jump to content
Soma

MarkupSimpleNavigation

Recommended Posts

I have played with selectors a little.

My task is solved by

$options = array('selector' => 'id|parent=1006|1003');

1006 and 1003 - ids of "Want in menu 1|2" in my structure.

So we can use multiple "parents" =)

  • Like 1

Share this post


Link to post
Share on other sites

Just wanted to add that parent=1006|1003 will only give direct children of those two pages and not recursively all children and grandchildren... So once you get on 3rd level it will stop. This may not an issue just a limit of this use.

There's a select field has_parent=1006 which does include all that are in that parent with all subchilds, though it doesn't allow for multiple only one ID.

So going templates or checkbox way is most flexible and solid solution.

Edit: you could work around the limit also with something like this (being creative)

<ul class="nav">
<?php echo $nav->render(array('selector' => 'id|has_parent=1006', 'outer_tpl' => '||' )); // outer ul empty ?>
<?php echo $nav->render(array('selector' => 'id|has_parent=1003', 'outer_tpl' => '||' )); ?>
</ul>
  • Like 1

Share this post


Link to post
Share on other sites

You could also have a template "redirect" with only a title and a page field (single page) to select any page you want to go.

Then in the code you should be able to write

array('item_tpl' => '<a href="{redirect_page.url|url}">{title}</a>')

So it would take the url of the referenced page in the page field if found, or if not it takes the url of the page itself. Assuming the page field is named "redirect_page".

Haven't tried but should work.

I tried this but all I am getting is a "page you were looking for is not found" error. The URL is not displaying the redirected page URL. I'm probably doing something wrong since I am still very new to all this.  Great, great module btw!! Thanks for making!

Share this post


Link to post
Share on other sites

@n0sleeves

No you're not doing anything wrong. As I said I didn't test this, just thought it would work.

I found it's not working the way I thought with a page field "pagefieldname.url". MarkupSimpleNavigation uses the $page->get("fieldname|otherfieldname") method to get  values, and subfields don't seem to work here.

So I just went and added this feature so you can now in 1.1.8 use page fields like 'redirect_page' (without url) and it will detect it's a page and spit its url.

To make it work the page field has to be set to "Single Page or false".

'item_tpl' => '<a href="{redirect_page|url}">{title}</a>'

This is now in pushed and available on modules repository.

  • Like 1

Share this post


Link to post
Share on other sites

So I just went and added this feature so you can now in 1.1.8 use page fields like 'redirect_page' (without url) and it will detect it's a page and spit its url.

To make it work the page field has to be set to "Single Page or false".

I have that set. Is there anything else I need to set?

'item_tpl' => '<a href="{redirect_page|url}">{title}</a>'

This is now in pushed and available on modules repository.

Wow, that was fast! You are amazing! Unfortunetly, it's still throwing the same error to me as before, "The page you were looking for is not found.Please use our search engine or navigation above to find the page.".

Here is my php code below in case I'm missing something.

$treeMenu = $modules->get("MarkupSimpleNavigation"); 
$rootPage = $pages->get("/photos/");

echo $treeMenu->render( array(
'collapsed' => true, 
 'item_tpl' => '<a href="{redirect_page|url}">{title}</a>'
), null, $rootPage); 

Thanks so much!

Share this post


Link to post
Share on other sites

Well it works. This module doesnt throw 404 so there must be something wrong with the url the item gets from the page field. Make sure the redirect_page is populated with a page that is viewable.

Share this post


Link to post
Share on other sites

Hi Soma and All,

Thanks, Soma, for building this excellent MODX Wayfarer replacement. I've got it working with a special selector query,

'show_in_menu=1', which makes me happy, happy.

But now, I've been looking around for some actual CSS examples, the way the old Wayfinder page used to have.

You know, working examples of using it for a dropdown / flyout menu, etc.

Does anyone have any links that use Soma's module? Menu CSS details make my brain freeze. I'm not sure why. :-)

Thanks!

Peter

Share this post


Link to post
Share on other sites

Dear Soma,

Also, as a followup, is there a way to add a parameter to the module so that a url or redirect_url could have a flag set in the page to open the url in a new tab?

I.e. "target=_blank" if "open_in_new_tab=1" ?

MODX had that with weblinks, and it was very cool. Most of the external url redirects that would appear on a menu (in my case) should be opened in a new tab.

I added the target=_blank to the parameter:

    'item_tpl' => '<a href="{redirect_url|url}" target="_blank">{title}</a>',

but then that opens all links in a new tab.

Thanks!

Peter

Share this post


Link to post
Share on other sites

Hey Peter glad you like it.

1. I think there's tons of examples out there. I agree it can be tricky if you're not into it so much. I often use a drop-down script (with some basic CSS) I modified some time ago, it's also used in my Teflon theme. https://github.com/somatonic/droppy it doesn't require anything except jQuery and some CSS. There's also CSS only ways to do it.

2. I'm a little careful not to add even more options. This I agree can be handy, since it's also possible use external urls.

I think there's different ways to achieve it already what you want without adding more. xtemplates, xitem_tpl, options for example, but it would only be possible to add it to all links that have the template you define there.

But there's another way that is possible since a couple versions. Adding a hook to the link item being constructed and modify it. Here simple example for use in templates:

function getTagsString(HookEvent $event){
    $tpl = $event->arguments[0]; // the template string
    $page = $event->arguments[1]; // the page getting rendered
    if($page->open_blank){ 
        // $event->return is the complete link you get from the hook, modify to you needs
        $event->return = str_replace('href=','target="_blank" href=', $event->return);
    }
}
$treeMenu->addHookAfter('getTagsString', null, "getTagsString");

echo $treeMenu->render(); 
  • Like 1

Share this post


Link to post
Share on other sites

Dear Soma,

Thanks for that! Hey, now I'm using my Very First Hook! Woohoo! :-)

Your code works like a charm. Am I correct in thinking that I can rename the 3rd parameter, i.e. the local function?

That's what I did, and it seems to work. Here's my code:

function redirect_url_target_fix(HookEvent $event)
      {
      $page = $event->arguments[1];

      if($page->open_in_new_tab)
            {
            $event->return = str_replace('href=','target="_blank" href=', $event->return);
            }
      }

$treeMenu->addHookAfter('getTagsString', null, "redirect_url_target_fix");

echo $treeMenu->render($tree_menu_options); 

Best regards,

Peter

  • Like 1

Share this post


Link to post
Share on other sites

I'm using Font Awesome, and wanted to be able to add icon markup to parent pages only.

Soma mentioned using "xtemplates", but in my case parent and child pages all use the same template.

So after I flew to Switzerland to hand Soma a beer, he suggested I use a hook.

This may be useful to someone else, so here's what I did:

1. add a text field called "icon" to your template.

2. add the code below before you call $treeMenu->render();

function addIcon(HookEvent $event){
$page = $event->arguments[1];
    if ($page->icon){
        $event->return = "<a href='{$page->url}'><i class='icon icon-{$page->icon}'></i> {$page->title}</a>";
    }
} 

$treeMenu->addHookAfter('getTagsString', null, "addIcon");
  • Like 4

Share this post


Link to post
Share on other sites

what about 2.3 compatibility?

I couldn't find the module in the list of 2.3 compatible modules...

No it's 2.3 compatible, but every new version has a new checkbox to check and I haven't done it yet. I think there's many modules that suffer from this.

  • Like 1

Share this post


Link to post
Share on other sites

No it's 2.3 compatible, but every new version has a new checkbox to check and I haven't done it yet. I think there's many modules that suffer from this.

ahh super! thx

Share this post


Link to post
Share on other sites

Soma (or anyone else that might know),

I need to have some role specific pages in my navigation (i.e. only a user with "travel admin" role sees the "travel admin" navigation item).

I'm using, Custom Page Roles module to define access on a per page basis—so I'm able set the view access as needed. However, those pages still appear in the navigation for all users.

I would usually exclude pages from the navigation by setting the page to hidden, but that won't work in this case, because the page would be hidden from everyone.

Is it possible to hide navigation items when the page is not viewable to that user?

Share this post


Link to post
Share on other sites

Hi Tom, I did this but it was a while ago and I am up against a deadline so can't spend long right now but just in case this code is self explanatory I paste it in the hope it helps, I am 99.9% sure I solved it with the great Soma's help ;)

$nav = $modules->get("MarkupSimpleNavigation"); // load the module and have an instance kept in $nav var
$options = array(
        'levels' => true,
        'show_root' => true,
        'item_tpl' => '<a href="{url}">{title} <em>{headline}</em></a>',
        'item_current_tpl' => '<a href="{url}">{title} <em>{headline}</em></a>',
        'xtemplates' => 'editors_only',
        'xitem_tpl' => '<a class="editors_only" href="{url}">{title} <span>Editors only</span><em>{headline}</em></a>',
        'xitem_current_tpl' => '<a href="{url}">{title} <em>{headline}</em></a>'
);
echo $nav->render($options);

Hope it helps!

Share this post


Link to post
Share on other sites

Thanks Alan,

I think that solution still requires I use a separate template to define view access - right?

I'm building an admin area and will end up with a variety of different roles (some of which only need access to a single additional page).

Adding new templates just to manage access could get messy quickly in this case. Custom Page Roles is perfect—assuming there's a way to make it play nicely with MarkupSimpleNavigation.

Share this post


Link to post
Share on other sites

Soma (or anyone else that might know),

I need to have some role specific pages in my navigation (i.e. only a user with "travel admin" role sees the "travel admin" navigation item).

I'm using, Custom Page Roles module to define access on a per page basis—so I'm able set the view access as needed. However, those pages still appear in the navigation for all users.

I would usually exclude pages from the navigation by setting the page to hidden, but that won't work in this case, because the page would be hidden from everyone.

Is it possible to hide navigation items when the page is not viewable to that user?

The CustomPageRoles module is alpha, proof of concept and it says that pages still will be rendered in navigation. You'd have to exclude them when cycling the pages in the loop with $page->viewable().

But implementing this check in the modules manager would get kinda complicated and result in some potential problems with how it all works together.

The MarkupSimpleNavigation is access aware, but CustomPageRoles doesn't exclude pages when using with find() or children() calls, that's why it doesn't work also with MSN (heh).

You can do use page_roles (page field) to do what you want with a simple check for user roles simply with this:

echo $treeMenu->render(array("selector" => "page_roles={$user->roles}"));

Because of the use of a selector you have to add and define page roles for all pages you have in navigation. It's not using the viewable access method, but simply checking the page field for if any of the user's roles is added.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks Soma,

That method works. :)

The MarkupSimpleNavigation is access aware

When I was just trying to use templates to define access it didn't seem to be access aware.

Possibly because defining a root page?

$rootPage = $pages->get("/faculty/");

Edit: Hmm, nope, doesn't seem to be access aware even without that.

Share this post


Link to post
Share on other sites

If the /faculty/ template does have access rights set, yes then it wouldn't work as you get the page explicitly with get("/faculty/").

But for children when I remove view access for a role they won't show up in navigation unless you explicitly check the option to show them in lists and searches.

  • Like 1

Share this post


Link to post
Share on other sites

Yep, that was it — /faculty/ didn't have access rights set.

My brain gets scrambled at times with access control, especially when jumping between template based and page based control.

Is it beer:30 yet?

;)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By gebeer
      Although the PW backend is really intuitive, ever so often my clients need some assistance. Be it they are not so tech savvy or they are not working in the backend often.
      For those cases it is nice to make some help videos available to editors. This is what this module does.
      ProcessHelpVideos Module
      A Process module to display help videos for the ProcessWire CMS. It can be used to make help videos (screencasts) available to content editors.
      This module adds a 'Help Videos" section to the ProcessWire backend. The help videos are accessible through an automatically created page in the Admin page tree. You can add your help videos as pages in the page tree. The module adds a hidden page to the page tree that acts as parent page for the help video pages. All necessary fields and templates will be installed automatically. If there are already a CKEditor field and/or a file field for mp4 files installed in the system, the module will use those. Otherwise it will create the necessary fields. Also the necessary templates for the parent help videos page and it's children are created on module install. The module installs a permission process-helpvideos. Every user role that should have access to the help video section, needs this permission. I use the help video approach on quite a few production sites. It is stable so far and well received by site owners/editors. Up until now I installed required fields, templates and pages manually and then added the module. Now I added all this logic to the install method of the module and it should be ready to share.
      The module and further description on how to use it is available on github: https://github.com/gebeer/ProcessHelpVideos
      If you like to give it a try, I am happy to receive your comments/suggestions here.
    • By Robin S
      A module created in response to the topic here:
      Page List Select Multiple Quickly
      Modifies PageListSelectMultiple to allow you to select multiple pages without the tree closing every time you select a page.
      The screencast says it all:

       
      https://github.com/Toutouwai/PageListSelectMultipleQuickly
      https://modules.processwire.com/modules/page-list-select-multiple-quickly/
    • By gebeer
      Hello all,
      sharing my new module FieldtypeImagePicker. It provides a configurable input field for choosing any type of image from a predefined folder.
      The need for it came up because a client had a custom SVG icon set and I wanted the editors to be able to choose an icon in the page editor.
      It can also be used to offer a choice of images that are used site-wide without having to upload them to individual pages.
      There are no image manipulation methods like with the native PW image field.
      Module and full description can be found on github https://github.com/gebeer/FieldtypeImagePicker
      Kudos to @Martijn Geerts. I used his module FieldTypeSelectFile as a base to build upon.
      Here's how the input field looks like in the page editor:

      Hope it can be of use to someone.
      If you like to give it a try, I'm happy to hear your comments or suggestions for improvement. Eventually this will go in the module directory soon, too.
    • By bernhard
      @Sergio asked about the pdf creation process in the showcase thread about my 360° feedback/survey tool and so I went ahead and set my little pdf helper module to public.
      Description from PW Weekly:
       
      Modules Directory: https://modules.processwire.com/modules/rock-pdf/
      Download & Docs: https://github.com/BernhardBaumrock/RockPDF
       
      You can combine it easily with RockReplacer: 
      See also a little showcase of the RockPdf module in this thread:
       
    • By ukyo
      FieldtypeFontIconPicker
      Supported Icon Libraries
      FontAwesome 4.7.0 Uikit 3.0.34 IonicIcons 2.0.1 Cahangelog
      NOTE: Module store data without prefix, you need to add "prefix" when you want to show your icon on front-end, because some of front-end frameworks using font-awesome with different "prefix".
      Module will search site/modules/**/configs/IconPicker.*.php and site/templates/IconPicker.*.php paths for FieldtypeFontIconPicker config files.
      All config files need to return a PHP ARRAY like examples.
      Example config file : create your own icon set.
      File location is site/configs/IconPicker.example.php
      <?php namespace ProcessWire; /** * IconPicker : Custom Icons */ return [ "name" => "my-custom-icons", "title" => "My Custom Icon Set", "version" => "1.0.0", "styles" => array( wire("config")->urls->templates . "dist/css/my-custom-icons.css" ), "scripts" => array( wire("config")->urls->templates . "dist/js/my-custom-icons.js" ), "categorized" => true, "attributes" => array(), "icons" => array( "brand-icons" => array( "title" => "Brand Icons", "icons" => array( "google", "facebook", "twitter", "instagram" ) ), "flag-icons" => array( "title" => "Flag Icons", "icons" => array( "tr", "gb", "us", "it", "de", "nl", "fr" ) ) ) ]; Example config file : use existing and extend it.
      File location is site/configs/IconPicker.altivebir.php
      <?php namespace ProcessWire; /** * IconPicker : Existing & Extend */ $resource = include wire("config")->paths->siteModules . "FieldtypeFontIconPicker/configs/IconPicker.uikit.php"; $url = wire("config")->urls->templates . "dist"; $resource["scripts"] = array_merge($resource["scripts"], ["{$url}/js/Altivebir.Icon.min.js"]); $resource["icons"]["flag-icons"] = [ "title" => "Flag Icons", "icons" => array("tr", "en", "fr", "us", "it", "de") ]; $resource["icons"]["brand-icons"]["icons"] = array_merge($resource["icons"]["brand-icons"]["icons"], array( "altivebir" )); return $resource; After you add your custom config file, you will see your config file on library select box. Library Title (Location Folder Name).

      If your library categorized and if you have categorized icons set like uikit and fontawesome libraries, you will have category limitation options per icon field or leave it empty for allow all categories (default).

      Example : output
      if ($icon = $page->get("iconField")) { echo "<i class='prefix-{$icon}' />"; } MarkupFontIconPicker Usage
      // MarkupFontIconPicker::render(YourIconField=string, Options=array) echo MarkupFontIconPicker::render($page->YourIconField, [ 'prefix' => 'uk-icon-', // Icon class prefix, if you have different prefix, default is : "fa fa-" 'tag' => 'span', // Icon tag default is : "i" 'class' => 'fa-lg', // If you have extra cutom classes, for example : icons sizes, Array or Sting value 'style' => 'your custom styles if you have' // Array or String Value ]); Theme support

      Search support

      Category support

       
×
×
  • Create New...