We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32678
    • 290 Posts
    I'm using Wayfinder to generate navigation for a single page website. The nav list is comprised of anchor links, with each page section generated from discreet resources and pulled into the template with getResources.

    I seek to use page id + named anchor (i.e. 1#section1, 1#section2, etc.) in an output filter, as follows:
    [[*id:is=`1`:or:is=`1#home`:then=``:else=`<div>Some content</div>`]]


    I've also tried named anchors where I do want the content to show. Neither approach functions as intended - any ideas on how to make this work, or alternatives?

    Thanks!
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Well, that won't work since [[*id]] will always be the ID of the current resource, it will never return anything more than that ID.

      I think you'll need to have that in the tpl chunk used for the getResources snippet.
      [[+id:is=`1`:then=``:else=`<div>some content</div>`]]


      Or you can even use different chunk tpls for the first item, which would I presume be #1
      http://rtfm.modx.com/extras/revo/getresources#getResources-TemplatingProperties
        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
        • 32678
        • 290 Posts
        Quote from: sottwell at Jan 15, 2015, 05:26 PM
        Well, that won't work since [[*id]] will always be the ID of the current resource, it will never return anything more than that ID.

        I think you'll need to have that in the tpl chunk used for the getResources snippet.
        [[+id:is=`1`:then=``:else=`<div>some content</div>`]]


        Or you can even use different chunk tpls for the first item, which would I presume be #1
        http://rtfm.modx.com/extras/revo/getresources#getResources-TemplatingProperties

        Both great ideas! Unfortunately, the element in question exists higher in the document than the tpl chunk, so varying these doesn't work. I tried your suggestion for the placeholder, just to see if it would function, but it did not. The page does not refresh moving from anchor to anchor, so perhaps the system doesn't recognize the different panels?
          • 22427
          • 793 Posts
          Not sure to have fully understood your intention, but you could try a custom snippet, say "foo", with a property "section":

          Code of snippet "foo":
          <?php
          $output="<div>Some content</div>";
          if ( ($section = "1") or (section == "1#home") ) {
              $output = "";
          };
          return $output;
          Then call it this way:
          [[foo? &section=`...whatever.... `]]
            • 32678
            • 290 Posts
            Quote from: ottogal at Jan 17, 2015, 02:04 AM
            Not sure to have fully understood your intention, but you could try a custom snippet, say "foo", with a property "section":

            Code of snippet "foo":
            <!--?php
            $output="<div-->Some content";
            if ( ($section = "1") or (section == "1#home") ) {
                $output = "";
            };
            
            return $output;
            Then call it this way:
            [[foo? &section=`...whatever.... `]]

            Thanks. I'm essentially unfamiliar with PHP beyond knowing that it exists so... wink

            This would need to be an if else statement, and also needs to detect the section being displayed by the browser from the site template, and not the getResources chunk.

            I have a singe-page site and want to hide its nav bar logo when the user is on the 'home' page, while showing it everywhere else. Using section for this feasibly works since each 'page' is wrapped within a section element that has a discreet #id.

            This would be the statement, or something like it, but since this snippet would be placed in the site template and not the getResources chunk I assume it isn't enough to handle the detection.

            $output="<div-->Some content";
            if ($section = "home") {
                $output = "";
            } else {
                echo $output;
            }; 
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              $output="<div-->Some content";
              if ($section = "home") {
                  return "";
              } else {
                  return $output;
              }


              Usually this sort of thing is done in Javascript on the browser. The menu bar will have a class that is removed/added depending where the page has scrolled to. Then CSS specified that the menu bar is hidden if it has (or does not have) the class.

              http://css-tricks.com/forums/topic/add-class-depending-on-scrolling/
                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