MODxI recently began a MODx forum thread looking for community assistance with solving a Wayfinder navigation issue. I was eventually able to tackle the output issue with my own solution (below), but since this thread has been reactivated by someone else asking for my solution I felt it was reasonable to post a version of this here as well.

The Problem

I had a design that required only the output of the current directory structure be displayed as the user navigates through the site. So, if the directory structure looks like this:

Home
About us
    History
    Mission
Contact us
    Telephone
    Address

and the user is in About Us, then the output should be:

About us
    History
    Mission

conversely, if the user is in Contact Us the output would be:

Contact us
    Telephone
    Address

The problem here is the output generated by the Wayfinder snippet does not provide the ability to isolate all the elements in this manner and still retain the directory name as a navigational link.

The Solution

Create a chunk, {{getFieldid}} with the snippet call:

[!GetField? &docid=`[*parent*]` &field=`id`!]

then create another chunk, {{getFieldpt}} with the snippet call:

[!GetField? &docid=`[*parent*]` &field=`pagetitle`!]

Once the parent page title and parent document id is isolated a third chunk could then be created, {{getFieldlink}} to contain the combined elements and generate a link to the parent directory in which the user is located:

<a href="[~{{getFieldid}}~]" title="{{getFieldpt}}">{{getFieldpt}}</a>

Next, call in the {{getFieldlink}} chunk above a Wayfinder call,

[!Wayfinder? &startId=`[[UltimateParent? &topLevel=`1`]]`!]

and then style the output with CSS.


View Comments on “Navigation – Wayfinder & getField snippets”

You can track this conversation through its atom feed.

  1. My Favorite MODx Resources | Greg Smart says:

    [...] It allows you to look up the document tree and retrieve fields from parent documents. In a previous post I outlined my method for piecing together code from multiple getField call [...]

  2. kc64 says:

    I'm enjoying your blog greatly. When I saw this post, it reminded me of a very similar problem I had. I thought you might be interested in how I solved the problem.

    http://modxcms.com/forums/index.php/topic,26615...

  3. Gregory Smart says:

    Great to hear! Check out the comments on this post, they were very helpful: http://www.gregorysmart.com/2009/11/03/a-modx-n...

  4. kc64 says:

    I'm enjoying your blog greatly. When I saw this post, it reminded me of a very similar problem I had. I thought you might be interested in how I solved the problem.

    http://modxcms.com/forums/index.php/topic,26615...

  5. Gregory Smart says:

    Great to hear! Check out the comments on this post, they were very helpful: http://www.gregorysmart.com/2009/11/03/a-modx-n...

  6. Michael says:

    I'm havig trouble all output is empty. Do I need to install the GetField Snippet? I just did, same empty output…

  7. Gregory Smart says:

    Yes, install the GetField snippet. If you are not getting any output try changing the cache [[]] or [!!]. You can also try changing the page caching where the snippet call is located.

Leave a Reply

You must be logged in to post a comment.

blog comments powered by Disqus