Topic: Wayfinder, Display Parent and Children  (Read 3346 times)

Pages: [1]   Go Down

#1: 14-Jan-2009, 04:00 PM


pleth
Posts: 144

WWW
I am trying to use Wayfinder to display the Parent (with link) and it's children.

I have tried [!Wayfinder? &startId=`[[UltimateParent? &topLevel=`1`]]` &displayStart=`true`!], but this displays the Parent title only in <h> tags and not as a link. What's the correct call for creating this?
Greg

#2: 14-Jan-2009, 04:23 PM


paulp
Posts: 485

www.Campsites-in-wales Proudly powered by Modx

WWW
  [[Wayfinder? &startId=`0`]]

Should show everything
Its here at last:

www.campsites-in-wales.co.uk Campsite directory for campsites in Wales UK. Proudly powered my Modx

#3: 14-Jan-2009, 04:26 PM


pleth
Posts: 144

WWW
Thank you, but I am wanting to exclude everything but the directory I am in.
Greg

#4: 14-Jan-2009, 04:29 PM

kongondo
Posts: 1,390

I am trying to use Wayfinder to display the Parent (with link) and it's children.

I have tried [!Wayfinder? &startId=`[[UltimateParent? &topLevel=`1`]]` &displayStart=`true`!], but this displays the Parent title only in <h> tags and not as a link. What's the correct call for creating this?

I don't understand your question however, I can tell you that by setting &displayStart=`true` you are actually telling WF to use the startItemTpl as the highest container of the menu (under the condition that &startId is greater than 0). WF has an inbuilt startItemTpl which it will use in case you don't create one - it looks like these

Code:
<h2>[+wf.linktext+]</h2>[+wf.wrapper+]

That's why the parent item in your menu is enclosed in <h2> tags.... Smiley

cheers/k


#5: 14-Jan-2009, 04:32 PM


paulp
Posts: 485

www.Campsites-in-wales Proudly powered by Modx

WWW
Thank you, but I am wanting to exclude everything but the directory I am in.

Try

  [[Wayfinder? &startId=`0` &hideSubMenus=`true`]]
Its here at last:

www.campsites-in-wales.co.uk Campsite directory for campsites in Wales UK. Proudly powered my Modx

#6: 14-Jan-2009, 04:33 PM

kongondo
Posts: 1,390

Thank you, but I am wanting to exclude everything but the directory I am in.

By exclusion are you talking about one and only one directory? E.g.

Home
About us
    History
    Mission

Contact us


so, in the above e.g., do you mean you would want your menu to only show the parent folder "About us" and its children AND that "Home" and "Contact us" SHOULD not be included in the WF output? Or do you mean what PaulP has asked above, i.e. hide sub-menus of parent documents unless they are active?

/k

#7: 14-Jan-2009, 04:36 PM


pleth
Posts: 144

WWW
Exactly. If I am in the About us section you only see About us, History, Mission. If I am in the Contact us section you see Contact us, Telephone, and Address. I am just unable to generate the parent with the appropriate link using the code I posted.

Home
About us
    History
    Mission
Contact us
    Telephone
    Address
Greg

#8: 14-Jan-2009, 04:54 PM


pleth
Posts: 144

WWW
Thanks for your help guys. I think I figured it our using the FirstChildRedirect and GetField snippets.
Greg

#9: 15-Jan-2009, 01:59 AM

jb2009
Posts: 16

Hi guys

Having not tested the suggestions outlined above, I would like to seek clarification on the menu I would like to implement (which may be exactly the same!?). I want a menu that works like Reuters news site (http://www.reuters.com). That is, if you click on (e.g.) Entertainment in the left-hand menu, you are subsequently presented with:

...
Technology
Entertainment
  Film
  Music
  People
  ...


where the existing parent directories are displayed, as well as the children in the active directory. Is the suggestion made by paulp:

[[Wayfinder? &startId=`0` &hideSubMenus=`true`]]

the code that I am after to achieve this?

Many thanks,

JB

#10: 15-Jan-2009, 02:20 AM


paulp
Posts: 485

www.Campsites-in-wales Proudly powered by Modx

WWW
Yep, that should work
Its here at last:

www.campsites-in-wales.co.uk Campsite directory for campsites in Wales UK. Proudly powered my Modx

#11: 15-Jan-2009, 02:26 AM

jb2009
Posts: 16

Excellent! I will try that tonight then  Grin

Thanks Paul

#12: 5-Feb-2009, 09:41 AM


lesur
Posts: 20

JP

Hmm. 

This is what I have been trying to achieve for the past few days as well and have not been successful.  [[Wayfinder? &startId=`0` &hideSubMenus=`true`]] is not working in that it shows all of the menus at the root level (albeit without their children).

Using the example presented earlier, if I have

Home
About us
    History
    Mission
Contact us
    Telephone
    Address

then when I am in the "About us" document, the menu displayed is:

Home
About us
    History
    Mission
Contact us

I don't want Home or Contact us to show up and of course don't want to manually exclude them.

Pleth can you elaborate on what you did? 

I see the FirstChildRedirect snippet but not a GetField one and in any case have no idea how to use them.

#13: 5-Feb-2009, 10:08 AM


pleth
Posts: 144

WWW
Okay, bear with me on this one, it seems a little convoluted, but it does work...

I created a chunk, {{getFieldid}} with the snippet call: [!GetField? &docid=`[*parent*]` &field=`id`!]

I then created another chunk, {{getFieldpt}} with the snippet call: [!GetField? &docid=`[*parent*]` &field=`pagetitle`!]

I then created a third chunk, {{getFieldlink}} to contain the combined parent id and pagetitle as a link: <a href="[~{{getFieldid}}~]" title="{{getFieldpt}}">{{getFieldpt}}</a>

Next, I called in my {{getFieldlink}} above my Wayfinder call, [!Wayfinder? &startId=`[[UltimateParent? &topLevel=`1`]]`!] and then styled the output with CSS.

Almost forgot, I believe this to be the link to the getField snippet: http://modxcms.com/getField-667.html
Greg

#14: 6-Feb-2009, 12:58 PM


lesur
Posts: 20

JP

Wow.  Appreciate the concise yet detailed instructions. 

I couldn't get what you did to work for me as it was, but it allowed me to figure out how to make a snippet that does do it for me.  The problem was that getFieldid was getting then passing an empty link on to getFieldlink which in turn gave me a blank menu item pointing to nowhere.

For anyone interested, the snippet is:
Code:
<?php
$id
=$modx->documentObject['id'];
$fid $modx->getParent($id,1,'id');
if(
is_array($fid))
$bingo=implode(" "$fid);
if (
$bingo != "") {
$flpt=$modx->getChunk('getFieldpt');
return 
"<a href=\"[~$bingo~]\" title=\"$flpt\">$flpt</a>";
}
else 
return 
"$fid";
?>

Probably not the most optimized code, but like i said, it works;  that and two calls using wayfinder and I have the parent and children on all my pages.

JP

#15: 6-Feb-2009, 01:12 PM


pleth
Posts: 144

WWW
Now that I look at it I forgot to mention that my solution needs to have all the documents residing within a directory that uses a FirstChildRedirect on the parent and then the 1st document should not be displayed in the menu. I would imagine that was why you were getting a blank from the getField snippet. I told you it was convoluted!
Greg

#16: 21-Feb-2009, 03:54 PM

dsumanik
Posts: 6

Well I too required this as I wanted to Make Some simple blog navigation, especially on containers with alot of hidden from menu pages, here is what i did maybe someone could expand on it further.

Snippets Used (not all are necessary in the end) but they are all 3 good to have in your repertoire, id install em anyways they are tiny and quick to set up.

GetField  1.3beta - http://www.modxcms.com/getField-1.3-beta-1189.html
UltimateParent 1.3 - http://modxcms.com/UltimateParent-643.html
FirstChildRedirect 1.1- http://www.modxcms.com/FirstChildRedirect-1.1-840.html

Now Continuing in the work of the above posters.......both methods listed here seem to work, however i cleaned it up a bit.

I created the chunks as per pleth's post above

{{getFieldid}} ==  [!GetField? &docid=`[*parent*]` &field=`id`!]
{{getFieldpt}} == [!GetField? &docid=`[*parent*]` &field=`pagetitle`!]
{{getFieldlink}} ==<a href="[~{{getFieldid}}~]" title="{{getFieldpt}}">{{getFieldpt}}</a>

Regardless of FirstChildRedirect in the parent folder or not, the chunk {{getFieldlink}} was able to return the appropriately titled Parent Link.

Alternatively, you could use lesur's Method and create a new snipped called

[[ParentLink]] ==

Code:
<?php
$id
=$modx->documentObject['id'];
$fid $modx->getParent($id,1,'id');
if(
is_array($fid))
$bingo=implode(" "$fid);
if (
$bingo != "") {
$flpt=$modx->getChunk('getFieldpt');
return 
"<a href=\"[~$bingo~]\" title=\"$flpt\">$flpt</a>";
}
else 
return 
"$fid";
?>

This also Returns the same a result as per pleth's post.

Which one is cleaner?

I dunno I'm no expert but they both work.

Moving on, I created a new Chunk called

{{BlogNav}}

This chunk will be used to provide basic navigation between all hidden documents in a single directory as well *only* that document's immediate parent. This allows you to have navigation between individual pages within a blog without the 99 blog posts form a trip in the main menu, or the clutter of ditto calls on each page yet it still provides the navigation, even if the pages are hidden from the main menu.

For Instance it will return this, regardless of where the documents reside in the main site's hierarchy, even if they are hidden:

  • MY Blog
    • Post1
    • Post2
    • Post3
    • Post 4
    • Post 99

So to finish it off this is the master chunk you need:

{{BlogNav}} ==

<div id="blognav">
  <ul>
    <li>{{getFieldlink}}
      [!Wayfinder? &startId=`[*parent*]` &ignoreHidden=`true`!]
    </li>
    <li>[[ParentLink]]</li>
  </ul>
</div>

I used both  {{getFieldlink}} &  [[ParentLink]] To show it could be done either way or both.

Now Add some CSS Styling:

#blognav {
text-align:center;
}

#blognav li, #blognav ul {
display:inline;
margin:0px;
list-style-type:none;
}

Now put the {{BlogNav}} call in the bottom of any document or add it to your template and you will get a nice navmenu output in the bottom of your blog post in the same order as your menu sorting within modx...just like i used on my site while i was in Hawaii:

http://www.mmayukon.ca/training/blogs/mauiblog/mauitease.html

Side Notes and Ideas for future improvement:

The next step would be to combine this with pagination or Breadcrumbs somehow. I wouldn't know how to do that though. Also, Another Interesting Result of this experiment is that I Made another Chunk using getfield that returns the parent 2 steps up from the source documents ID.

This could also be useful in certain circumstances I think.

I called it:

{{DoubleParent}} == [!GetField? &docid=`[*parent*]`&field=`id`&parent=`1`&parentLevel=`1`!]



« Last Edit: 21-Feb-2009, 04:47 PM by dsumanik »

#17: 24-Feb-2009, 07:31 PM

sirius
Posts: 6

Why is this getting so complicated? The original problem is that pleth wants &displayStart to generates <a> rather than <h2>

The Wayfinder &startItemTpl parameter is dedicated to this problem.

1: Tell Wayfinder to use your own start_item_template.
Code:
[!Wayfinder? &displayStart=`true` &startItemTpl=`your_custom_start_item_template_chunk`!]

2: make your_custom_start_item_template_chunk something like this:
Code:
<h2><a href="[+wf.link+]">[+wf.linktext+]</a></h2>[+wf.wrapper+]

3: Clear cache and test the result

#18: 24-Feb-2009, 07:52 PM


pleth
Posts: 144

WWW
Thanks. I knew there had to be a simpler solution.
Greg

#19: 19-May-2010, 07:35 AM

blakewilliams
Posts: 5

This is kind of what I am looking for - the only problem I have, is that seeing as I have used &displaystart=TRUE, even where there are no child categories, I get an empty menu

[!Wayfinder?startId=`[*id*]`  &level=`2` &hideSubMenus=`1` &outerTpl=`dynamicSide` &displayStart=`TRUE`!]

any solutions?  Basically if there are subcategories to the page I'm on, I want the subcategories in a side nav - if there arent, then I want nothing ot appear there.

[!Wayfinder?startId=`[*id*]`  &level=`2` &hideSubMenus=`1` &outerTpl=`dynamicSide` &displayStart=`TRUE`!]
Pages: [1]   Go Up
0 Members and 1 Guest are viewing this topic.