We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10988
    • 14 Posts
    Hi all

    Just looking for a way to set the "active" resource for Wayfinder.

    I have a menu that’s not driven by the current resource where I’d like to programmatically set the active ID for styling purposes. Is this at all possible?

    Cheers,
    Phil
      • 26931
      • 2,314 Posts
      &selfClass=`youractivecssclass`
      in the Wayfinder call?
      http://www.muddydogpaws.com/development/wayfinder/parameters.html
        • 10988
        • 14 Posts
        Sorry, when I said for styling purposes I meant "tell Wayfinder which item is the active / current one so it sets the class on that item".

        I currently have this
        [[Wayfinder? &displayStart=`true` &startId=`x`]]


        I want to be able to tell Wayfinder that resource "y" which is part of "x"’s tree is the current / active resource.

        After looking through the Wayfinder code, I may just have to write it in myself as the active resource is determined by a direct call to
        $this->modx->resource->get('id')
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Wayfinder has two parameters for setting classnames for the active resource. One is for only the active resource &selfClass, the other is for the active resource and its parents all the way up the tree &hereClass. There are also a number of specific tpls to set for these: &hereTpl, &innerHereTpl, &activeParentRowTpl.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 10988
            • 14 Posts
            Thanks Susan. Just to clarify, I’m not trying to set the active classname, rather I’m trying to set the active resource ID.

            To flesh out the use-case a little;

            I have a page (resource) that calls the Wayfinder snippet to display a menu, using a &startId that is not a parent of the current page. This means that no item in the generated menu will be set as active.
            What I’d like to do is tell Wayfinder that a child resource of the startId is the active page so that it will add the appropriate classnames to that page and its parents.

            As I mentioned above, the way Wayfinder determines the current resource ID is hard-coded and not configurable. I will have to create a custom snippet. What I’ll eventually come up with is something like
            [[CustomWayfinder? &startId=`x` &activeId=`y`]]
            
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              hmmm... yeah, that is a bit different. Perhaps you could add the class in the link attributes field and use [+wf.attributes+] in the tpl? Although that won’t solve the parents problem...
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 10988
                • 14 Posts
                Just to follow up on this... Shaun has implemented a patch I submitted via github and Wayfinder now supports the "hereId" parameter.
                  • 28120
                  • 380 Posts
                  not sure if this is the same issue but I’ve got a snippet activeResource that I call

                  [[!activeResource? &activeID=`[[+id]]` ]]

                  <?php
                  $cssClass = 'normal';
                  if($activeID == $modx->documentIdentifier) {
                  $cssClass = 'active';
                  }
                  return $cssClass;