Jump to content


Photo

MarkupSimpleNavigation

Module

  • Please log in to reply
208 replies to this topic

#41 alanfluff

alanfluff

    Sr. Member

  • Members
  • PipPipPipPip
  • 439 posts
  • 128

  • LocationOttawa, Canada

Posted 14 April 2012 - 01:28 PM

Would there be an easy way to use MarkupSimpleNavigation and maybe something like in_array()(?) to check if an ID (that will come from a GET so we must test it) was the same as one of the pages that the navigation would normally display?

I assume one initial step would be working out if I can configure the options for MarkupSimpleNavigation so it only returns the IDs of pages (no markup) and it returns all pages one would want the public to see, the same list one would have in a sitemap.xml.

I'll take a longer look at the options the very good documentation has to see how I might do this.

Update:
Progress, this

$options = array(
//      'parent_class' => '',
//      'current_class' => '',
//      'has_children_class' => '',
        'outer_tpl' => '',
        'inner_tpl' => '',
        'list_tpl' => '',
        'item_tpl' => '{id}',
        'item_current_tpl' => '',
//        'item_current' => '{title}'
);
echo $nav->render($options);
returns only the IDs (with whitespace, dunno if that matters as regards interpreting the o/p with something like in_array(). I'll see...

Edited by alan, 14 April 2012 - 01:46 PM.


#42 Soma

Soma

    Hero Member

  • Moderators
  • 3,421 posts
  • 1944

  • LocationSH, Switzerland

Posted 14 April 2012 - 02:51 PM

Glad you figured it out somehow. Yes I also thought something like this it could work getting only the ids. But this module is usually used for markup generation.

I still don't understand completely what you're trying to do though, you could try this:


$options = array(
		'outer_tpl' => '',
		'inner_tpl' => '',
		'list_tpl' => '{id} ',
		'item_tpl' => '',
		'item_current_tpl' => ''
);
$array_ids = explode(" ",trim($nav->render($options));

@somartist | modules created | support me, flattr my work flattr.com


#43 alanfluff

alanfluff

    Sr. Member

  • Members
  • PipPipPipPip
  • 439 posts
  • 128

  • LocationOttawa, Canada

Posted 15 April 2012 - 10:26 AM

I still don't understand completely what you're trying to do though


:D Soma, you are in good company if you don't understand what I am doing — I am sure a lot of people feel the same; I don't understand me sometimes ;)

Joking aside, I am trying to check if an ID is for a page that is normally publicly visible or not. I plan to show a short-version permanent link to each page so if someone wants to tweet about (or email easily) a page, they can refer to:
example.com/p/1987
rather than having to refer to
example.com/animals/houses/the-squirrel-house/cheeky-the-red-squirrel-eating-some-cheese
My code uses a GET to check if a visitor has typed

example.com/p/1987
and I want the code to then check that 1987 is a valid page I want to allow sending them too, if not I will 404 or just show a message etc.

Edit: I tried your code like this:
$options = array(
				'outer_tpl' => '',
				'inner_tpl' => '',
				'list_tpl' => '{id} ',
				'item_tpl' => '',
				'item_current_tpl' => ''
);
$array_ids = explode(" ",trim($nav->render($options)));
echo $nav->render($options);
but it looks like list_tpl' => '{id} ' results in {id} {id} {id} {id} {id} {id} {id} etc being output rather than the actual ID numbers — but thank you for the clues I will keep working on it and if I solve this, repost here.


Edit 2: I typo'd, your code works (of course ;)) — thanks again for the help!

If I finish this functionality off I'd like to see if I can make it into a Module(!), but I don't want to get too excited yet, it's not even working ;)

Edited by alan, 15 April 2012 - 10:36 AM.


#44 Soma

Soma

    Hero Member

  • Moderators
  • 3,421 posts
  • 1944

  • LocationSH, Switzerland

Posted 15 April 2012 - 11:32 AM

Ah so you're trying to have an id permalink to pages (shortcut). I'm not sure if this woud help but this is how I would solve it.

Normally you would setup your tree to have pages that will be in the navigation, and set pages not in navigation to hidden. From there it would just be a simple check to see if the page (id) requested is not hidden.
if(!$pages->get($id)->isHidden()) $session->redirect($pages->get($id)->url);
	else $session->redirect($pages->get($config->http404PageID)->url);

Or you could add a field (checkbox) "not_permalink", and give that to templates you need. You could use it for single pages, or just the parent of a branch. So all children pages will either be shown or not.
if(!$pages->get($id)->parents->has("not_permalink=1") || $pages->get($id)->not_permalink == 0)  $session->redirect($pages->get($id)->url);
	else $session->redirect($pages->get($config->http404PageID)->url);

It depend a lot how you setup you page tree and how you make them appear in your navigation, but I'm sure you'll find a very simple solution. I think it can be as simple as a 2 line code and no module would be required.

@somartist | modules created | support me, flattr my work flattr.com


#45 alanfluff

alanfluff

    Sr. Member

  • Members
  • PipPipPipPip
  • 439 posts
  • 128

  • LocationOttawa, Canada

Posted 15 April 2012 - 11:34 AM

WoW! Thanks Soma, I thought it should be easy with the power of PWs API but my limited and the fun of trying other ways meant I was OK to try other routes such as re-purposing your cool module. Thanks again, I will try out your code here and see what I get!

#46 alanfluff

alanfluff

    Sr. Member

  • Members
  • PipPipPipPip
  • 439 posts
  • 128

  • LocationOttawa, Canada

Posted 15 April 2012 - 11:53 AM

OK, thanks to that code [Soma, thank you] without (yet) resorting to using the "not-permalink" option (which may be the way I have to go) the only pages I seem to have problems with are ones where when I try some IDs at random (to see if I can 'break' the system) result in a URL like this and a login prompt:
http://example.com.site/pw/repeaters/for-field-107/for-page-1188/
I'm now looking to see if there is an API way to detect if an ID is 'as a result of a repeater' or 'normal' (if that even makes sense).

#47 Soma

Soma

    Hero Member

  • Moderators
  • 3,421 posts
  • 1944

  • LocationSH, Switzerland

Posted 15 April 2012 - 12:10 PM

Since repeaters (pages) are in the admin section hidden. You could exlude them by id of the admin page.


$p = $pages->get($id);

if($p->isHidden() || $p->rootParent->id == 2)  $session->redirect($pages->get($config->http404PageID)->url) 
    else $session->redirect($p->url);;




I think if you want to exlude other branches you could try something like this.

$p = $pages->get($id);
if($p->isHidden() || $p->is("has_parent=2|10|1033")) $session->redirect($pages->get($config->http404PageID)->url);
    else $session->redirect($p->url);


NOt really tested but let me know if it doesn't work out.

@somartist | modules created | support me, flattr my work flattr.com


#48 SiNNuT

SiNNuT

    Sr. Member

  • Members
  • PipPipPipPip
  • 378 posts
  • 236

Posted 15 April 2012 - 07:46 PM

:D Soma, you are in good company if you don't understand what I am doing — I am sure a lot of people feel the same; I don't understand me sometimes ;)

Joking aside, I am trying to check if an ID is for a page that is normally publicly visible or not. I plan to show a short-version permanent link to each page so if someone wants to tweet about (or email easily) a page, they can refer to:

example.com/p/1987
rather than having to refer to
example.com/animals/houses/the-squirrel-house/cheeky-the-red-squirrel-eating-some-cheese


Allen; judging from a couple of recent threads i scanned your quite hung up on providing some short/perm link functions. Ofcourse, everyone has their own requirements for certain projects but i don't see the real benefit. Twitter auto-shortens links or use bit.ly or such services. In mail, where there's no 140 lmit i would rather have descriptive url than some id based url.

Allen; judging from a couple of recent threads i scanned you're quite hung up on providing some short/perm link functions. Ofcourse, everyone has their own requirements for certain projects but i don't see the real benefit. Twitter auto-shortens links or use bit.ly or such services. In mail, where there's no 140 lmit i would rather have descriptive url than some id based url.



#49 alanfluff

alanfluff

    Sr. Member

  • Members
  • PipPipPipPip
  • 439 posts
  • 128

  • LocationOttawa, Canada

Posted 16 April 2012 - 07:12 AM

Allen; judging from a couple of recent threads i scanned your quite hung up on providing some short/perm link functions. Ofcourse, everyone has their own requirements for certain projects but i don't see the real benefit. Twitter auto-shortens links or use bit.ly or such services. In mail, where there's no 140 lmit i would rather have descriptive url than some id based url.


@SiNNuT you're right, I certainly am trying to solve this, but I'm not hung up on it ;) just interested in finding the answer. And I agree with you about Twitter and that perhaps this is less important now:

Now Twitter self-shortens links <- insert debate if that's good here -> what I am trying to do is perhaps less important, but I like the idea of being able to refer to a page with an alternate, ultra-short, permanent URL.


But often I will still stick to using plain-text (not HTML) email and sometimes I want a short way to refer to a URL in an email. Although this may be an edge case it's enough to make me want to explore if I can do this easily with PW.

Added to that, solving a challenge like this is not only valuable for the resulting functionality, but also it makes me learn, and as I need all the learning I can get (being a bit weak at PHP and API/jQuery style constructions) I kept trying to solve this one.

I just hope one or more of the posts in the thread end up helping someone else, either directly or in some way I had not envisaged.

And thanks for your comments about bit.ly etc, I ended up choosing the Google shortener extension in Chrome a while back after that outage from one of the shortening services. And yes, wherever appropriate I think using full URLs is the best way to go. Cheers!

#50 alanfluff

alanfluff

    Sr. Member

  • Members
  • PipPipPipPip
  • 439 posts
  • 128

  • LocationOttawa, Canada

Posted 16 April 2012 - 07:16 AM

@Soma

...NOt really tested but let me know if it doesn't work out.

Thanks Soma! I will certainly post back to let you know and thanks again for the pointers :D

#51 alanfluff

alanfluff

    Sr. Member

  • Members
  • PipPipPipPip
  • 439 posts
  • 128

  • LocationOttawa, Canada

Posted 16 April 2012 - 08:30 AM

@Soma I used a line of your code and some new code from Ryan and it works. Thank you very much indeed again for your help.

#52 alanfluff

alanfluff

    Sr. Member

  • Members
  • PipPipPipPip
  • 439 posts
  • 128

  • LocationOttawa, Canada

Posted 13 May 2012 - 11:57 AM

@Soma; THANK you for your nav module, just used it again — brilliant.

#53 Soma

Soma

    Hero Member

  • Moderators
  • 3,421 posts
  • 1944

  • LocationSH, Switzerland

Posted 18 May 2012 - 02:47 PM

Hey alan, thanks! Glad you like it. :)

@somartist | modules created | support me, flattr my work flattr.com


#54 yellowled

yellowled

    Sr. Member

  • Members
  • PipPipPipPip
  • 183 posts
  • 118

  • LocationEutin, Germany

Posted 06 June 2012 - 07:50 PM

Okay, so I'm different. Usually, people want to exclude stuff from an automagically generated navigation – I would like to add stuff. :)

Let's see if I can explain this: I have a primary navigation which this module is just perfect for. But the site also has a secondary navigation in the footer, so there should be an item in the primary nav which skips to said secondary nav in the footer. So basically, I would have to append an item to the nav generated by the module, technically another list item containing a link to an anchor on the same page.

Conveniently, this "skip to service nav" item would be the last item of the primary navigation, so I came up with this:

'outer_tpl' => '<ul class="clearfix">||<li><a id="skip-to-service" href="#service">Service</a></li></ul>'

which works fine unless I'm on a page which has children (<li class="current has_children">). In that case, outer_tpl is "reset" to '<ul class="clearfix">||</ul>' or something, at least the "appended" list item is not rendered.

Not being a PHP coder myself, I can't figure out if this is intended behaviour of the module or maybe a bug. (Although I'm aware I might be misusing 'outer_tpl' here.) I also thought about different approaches to realize that kind of nav item, maybe by using a "dummy page" or something, but I can't figure out how to do that. (Suggestions welcome, of course.)

#55 Soma

Soma

    Hero Member

  • Moderators
  • 3,421 posts
  • 1944

  • LocationSH, Switzerland

Posted 07 June 2012 - 02:30 AM

Yeah it's a bug, thanks for finding it. Should be fixed in the last commit. Let me know if it works for you too.

@somartist | modules created | support me, flattr my work flattr.com


#56 yellowled

yellowled

    Sr. Member

  • Members
  • PipPipPipPip
  • 183 posts
  • 118

  • LocationEutin, Germany

Posted 07 June 2012 - 08:31 AM

Works like a charm, thanks. :)

#57 apeisa

apeisa

    Hero Member

  • Moderators
  • 2,586 posts
  • 906

  • LocationVihti, Finland

Posted 17 August 2012 - 02:19 AM

Soma: I have used your module in one project and I like it very much. Have worked without any worries. But now I have navigation scenario that I am not sure if it is possible with MarkupSimpleNavigation or should I code snippet for this.

Default view works like this (normal two levels deep):

LEVEL1 Page a
---LEVEL2 Page aa
---LEVEL2 Page ab
---LEVEL2 Page ac
LEVEL1 Page b
---LEVEL2 Page ba
---LEVEL2 Page bc
LEVEL1 Page c
---LEVEL2 Page ca


But when I go to level2, it should collapse that page and show level3 pages there, but not from other branches. Like this:

LEVEL1 Page a
---LEVEL2 Page aa
---LEVEL2 Page ab
------LEVEL3 Page aba
------LEVEL3 Page abb
---LEVEL2 Page ac
LEVEL1 Page b
---LEVEL2 Page ba
---LEVEL2 Page bc
LEVEL1 Page c
---LEVEL2 Page ca

Is this something that is possible with just settings?

#58 Soma

Soma

    Hero Member

  • Moderators
  • 3,421 posts
  • 1944

  • LocationSH, Switzerland

Posted 17 August 2012 - 06:14 AM

No its not possible. Kinda very special case.

Well u could try making it max levels 3 and hide third level with css and open on click.

@somartist | modules created | support me, flattr my work flattr.com


#59 apeisa

apeisa

    Hero Member

  • Moderators
  • 2,586 posts
  • 906

  • LocationVihti, Finland

Posted 17 August 2012 - 06:32 AM

True, should be possible with css. I'll go that route for now, thanks!

#60 MarcC

MarcC

    Sr. Member

  • Members
  • PipPipPipPip
  • 263 posts
  • 67

  • LocationCalifornia

Posted 05 October 2012 - 12:23 PM

Hi Soma, I just downloaded and installed this on a new site, and there's a weird problem:

I have pages like:

Home
About Us
More About Us
Even More About Us
Donate Online
Contact Us

If I click on "More About Us" above, the page loads fine. But, if I click on "About Us" from the "More About Us" page, I get a 404 Page Not Found error. The menu has prepended "/home/" to the URL instead of "/about-us/". So if I try to go to "Even More About Us," I also get a 404, because the URL is now "/home/even-more-about-us" instead of "/about-us/even-more-about-us"

Do you know what could cause this? I thought it might have to do with show_root but that wasn't it. Thanks!

I'm a freelance, processwire-using web designer based in california. work site | personal site | visuals






Also tagged with one or more of these keywords: Module

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users