k07n Posted April 7, 2013 Share Posted April 7, 2013 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" =) 1 Link to comment Share on other sites More sharing options...
Soma Posted April 7, 2013 Author Share Posted April 7, 2013 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> 1 Link to comment Share on other sites More sharing options...
n0sleeves Posted April 9, 2013 Share Posted April 9, 2013 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! Link to comment Share on other sites More sharing options...
Soma Posted April 9, 2013 Author Share Posted April 9, 2013 @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. 1 Link to comment Share on other sites More sharing options...
n0sleeves Posted April 10, 2013 Share Posted April 10, 2013 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! Link to comment Share on other sites More sharing options...
Soma Posted April 10, 2013 Author Share Posted April 10, 2013 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. Link to comment Share on other sites More sharing options...
n0sleeves Posted April 10, 2013 Share Posted April 10, 2013 It's working great! It was an error on my part My apologies Link to comment Share on other sites More sharing options...
Peter Falkenberg Brown Posted April 22, 2013 Share Posted April 22, 2013 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 Link to comment Share on other sites More sharing options...
Peter Falkenberg Brown Posted April 22, 2013 Share Posted April 22, 2013 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 Link to comment Share on other sites More sharing options...
Soma Posted April 22, 2013 Author Share Posted April 22, 2013 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(); 1 Link to comment Share on other sites More sharing options...
Peter Falkenberg Brown Posted April 23, 2013 Share Posted April 23, 2013 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 1 Link to comment Share on other sites More sharing options...
Martijn Geerts Posted April 23, 2013 Share Posted April 23, 2013 Thats correct. Link to comment Share on other sites More sharing options...
renobird Posted April 24, 2013 Share Posted April 24, 2013 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"); 4 Link to comment Share on other sites More sharing options...
wishbone Posted April 27, 2013 Share Posted April 27, 2013 what about 2.3 compatibility? I couldn't find the module in the list of 2.3 compatible modules... Link to comment Share on other sites More sharing options...
Soma Posted April 27, 2013 Author Share Posted April 27, 2013 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. 1 Link to comment Share on other sites More sharing options...
wishbone Posted April 28, 2013 Share Posted April 28, 2013 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 Link to comment Share on other sites More sharing options...
renobird Posted April 30, 2013 Share Posted April 30, 2013 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? Link to comment Share on other sites More sharing options...
alan Posted April 30, 2013 Share Posted April 30, 2013 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! Link to comment Share on other sites More sharing options...
renobird Posted April 30, 2013 Share Posted April 30, 2013 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. Link to comment Share on other sites More sharing options...
alan Posted April 30, 2013 Share Posted April 30, 2013 Ah, gotchya, sorry not able to help :/ Link to comment Share on other sites More sharing options...
Soma Posted May 1, 2013 Author Share Posted May 1, 2013 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. 1 Link to comment Share on other sites More sharing options...
apeisa Posted May 1, 2013 Share Posted May 1, 2013 Uncomment the line 20: https://github.com/apeisa/CustomPageRoles/blob/master/CustomPageRoles.module#L20 There were some side-effects to that, so test well and good luck 1 Link to comment Share on other sites More sharing options...
renobird Posted May 1, 2013 Share Posted May 1, 2013 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. Link to comment Share on other sites More sharing options...
Soma Posted May 1, 2013 Author Share Posted May 1, 2013 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. 1 Link to comment Share on other sites More sharing options...
renobird Posted May 1, 2013 Share Posted May 1, 2013 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? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now