Loader::helper('navigation') documentation??????

Permalink
Lately, I keep seeing people mention this helper in the forums and the fact that this is curiously absent from the documentation. The oldest date I see is 2009 and here we are almost 2012 and it is still not documented anywhere:

http://www.concrete5.org/documentation/...

Helpers
• Core User Interface
• Date & Time
• Encryption
• File MIME Types
• JSON
• Location Lists
• Numbers
• Ratings
• RSS Feeds
• Scrapbooks
• Sending Mail
• Spell Checking
• Text
• URLs
• Unique String Identifiers

I have searched extensively and all I keep finding are Forum posts about different auto nav set-ups with people including this line in their code without explanation:
$nh = Loader::helper('navigation');

and other threads where people advise "don't forget to call the navigation helper" and a few comments about the navigation helper such as, "strangely, this appears to be absent in the documentation."


I apparently need to use it for a PAGE LIST, which doesn't seem like it should be part of a navigation helper, really, and I'm not the first person who has been asking about documentation of this, so can we get some info in this thread about it, please? Thanks.

 
PatrickHeck replied on at Permalink Reply
PatrickHeck
I don't know of an extensive documentation but the helper is not that complex. You can use the API Docs as a starting point:http://www.concrete5.org/api/Helpers/NavigationHelper.html...
zoinks replied on at Permalink Reply
Thanks, that would be helpful if I was good at PHP, but unfortunately, it doesn't explain to non-PHP experts how it is used the way the other documentation does. While people who know their way around PHP probably appreciate a "bullet points" version, for anyone else additional words are required to fill int he blanks, however small those blanks might seem to you.

Based on that link, I have no clue how I would use that to achieve anything others have been suggesting to me in various threads.

Where do I insert the line of code, in my template or my view.php for the custom template I'm building? Then what? Apparently that gives me three methods to work with, but how? Some examples would be nice.

Take this for example... someone gave me the following custom PageList template instructions:

"I think the main bit you are after, slimmed right down to the essentials just be sure to include the navigation helper"
<?php 
   for ($i = 0; $i < count($cArray); $i++ ) {
      $cobj = $cArray[$i]; 
      $title = $i+1;?>
   <a href="<?php echo $nh->getLinkToCollection($cobj)?>"><?php echo $title?></a>
<?php   }

This was supposed to give me a PageList block with an output of
<<previous 1 2 3 4 5 etc... next >>

So that the page titles are replaced with numbers.
But, all I get is an error message.
PatrickHeck replied on at Permalink Reply
PatrickHeck
Well, helpers are usually used inside a template. This specific one basically has 3 things you can do with it:

* Get the URL of a page
* Get a link to a page
* Get the breadcrumbs for a page

For all this you need to know the Collection ID of the page in question.

So a very basic template that just prints the URL of the current page would be for example
<?php
$c = Page::getCurrentPage();
$nh = Loader::helper('navigation');?>
The current URL is: <?php echo $nh->getCollectionURL($c) ?>
zoinks replied on at Permalink Reply
Thank you... is there any downside to including the helper if you don't really need it in the template? Probably a fraction of a second slower, I guess.

Also, do you see any way this can be integrated with a custom PageList block? Or was this person likely giving me a custom Auto Nav block instead and just forgot to mention it?
jordanlev replied on at Permalink Reply
jordanlev
@PatrickHeck -- note that it's not a Collection ID you pass into the helper, but rather a collection object (which you can get if you have a collection ID by calling Page::getByID(cID) ).

Note that you can also get page url's via a path by using the View::url() function, for example:
<?php echo View::url('/about/employees'); ?>

...which is the same as this:
<?php
$page = Page::getByPath('/about/employees');
$nh = Loader::helper('navigation');
$nh->getCollectionURL($page);
?>


@zoinks - I don't think there's that much downside to including the helper if you don't need it (like you said, just a fraction of a millisecond, but it's probably already being loaded elsewhere in the stack so maybe not even that).

I have a PageList custom template available that is functionally the same as the built-in C5 template, but the code is much easier to work with, and is also commented to show you how to do different things with it -- might be helpful to you:
https://raw.github.com/jordanlev/c5_clean_block_templates/master/pag...
PatrickHeck replied on at Permalink Reply
PatrickHeck
True jordan, I overlooked that. Thanks for pointing it out.
zoinks replied on at Permalink Reply
I'm glad you contributed because I have used this before:

<?php echo View::url('/about/employees'); ?>
...after finding it on the forum somewhere and I have never loaded the navigation helper. So, it must be somewhere already loaded in by default. I'm glad about this because the project I was working on was already extremely difficult.

I think I know enough now to try to use this custom PageList template. Hope so...
programmieraffe replied on at Permalink Reply
programmieraffe
*push* This should really be in the developer docs...
zoinks replied on at Permalink Reply
thanks for bumping this... sad thing is, I just re-read it and have no inkling of what it is I learned about this last October. The above makes no sense to me now. Must have drank too much beer since then and destroyed all these brain cells.
jordanlev replied on at Permalink Reply
jordanlev
Looks like Matt on the core team just updated the docs to reflect this... thanks Matt!

http://www.concrete5.org/documentation/developers/helpers/navigatio...