We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20014
    • 200 Posts
    Ok have done some scroogling on this and have run across a couple threads, most dealing with phx plugin and since I am working on revo, I can’t seem to get this to work.

    I have three containers with getpage calls on them, these containers share the same template as the child pages they contain, but I need to insert navigation links on the children pages without them showing up on the container pages.

    is there a way that I can put a call in the template that asks: "if the parent is this contianer, this container, or this container, return this chunk"?

    I tried something like
    [[*parent:8,9,11=`[[+navchunk]]`]]
    I got this from a post here, but it didn’t go into detail, I was hoping I could use the id numbers, but of course, as is the case with a lot of my php attempts laugh, it didn’t work at all.
    I would like the chunk to appear only on children pages but not the actual parent page. I know I could do this with a template variable, but the less the client has to do the better (i.e. not having to remember to check a radial button or the like).
      • 3749
      • 24,544 Posts
      I’m not positive that I understand what you want, but I think this is it. It will put the navchunk on the page for all children of resources 8, 9, and 11 and will be much more efficient than using the PHX filter:

      [[!ShowNav?  &parents=`8,9,11` &chunk=`navchunk`]]


      <?php
      /* ShowNav snippet */
      
      $parentIds = explode(',',$parents);
      $output = '';
      
      if (in_array($modx->resource->get('id'),$parentIds) ){
         $output = $modx->getChunk($navchunk);
      }
      
      return $output;
      
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 20014
        • 200 Posts
        hi bob, just to clarify a bit, when someone goes to the conatainer page where the getpage call is they will see all the client’s articles listed there and this page will use the same template as the child page, so when a visitor clicks on the readmore link they go to another page with the same layout, but since this page has a specific parent, I want a chunk to show up on just the child page and not the container page.

        actually, I just tried it and got a fatal error, I am not trying to insert wayfinder or anything like that, matter of fact, what I am looking for is the ability to insert any type of chunk really depending on the parent’s id.
          • 3749
          • 24,544 Posts
          My bad, that should be:


          [[!ShowNav?  &parents=`8,9,11` &chunk=`navchunk`]]


          (corrected above). I must have been temporarily insane.

          Give it another try. I think it does what you want.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 20014
            • 200 Posts
            oh not to worry bob, I am just thankful you help me so much.
            I think I am still botching it,

            first a create a chunk and call it "mychunk"

            then I create snippet called "mysnippet" with your code like this:
            <?php
            $parentIds = explode(',',$parents);
            $output = '';
            
            if (in_array($this->resource->get('id'),$parentIds) ){
               $output = $modx->getChunk($mychunk);
            }
            
            return $output;

            I then tried to place the call
            [[!mysnippet?  &parents=`8,9,11` &chunk=`mychunk`]]

            in both the template and I get an exception:
            Fatal error: Using $this when not in object context in C:\sites\site_development_folder\core\cache\elements\modsnippet\28.include.cache.php on line 10

            I even tried to place the code onto the container folder, same result, I did scroogle it a bit though before hand and I know it has to deal with the class/object, but I am still unsure of where the error lies.
              • 3749
              • 24,544 Posts
              Sorry, I pasted the code from inside a class.

              It should be:

              if (in_array($modx->resource->get('id'),$parentIds) ){


              (fixed post above)
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 20014
                • 200 Posts
                sorry about taking my time getting back on this..
                I tried it and there are no errors, but the chunk I want revealed on the child pages doesn’t appear.

                could I do it with if/else, would the syntax be something like this:
                $current_docid = $modx->resource->get('parent_id');
                $output ='';
                
                if($current_docid ==8){
                    $output .='[[$this_chunk]]';
                }
                
                elseif($current_docid ==9){
                    $output .='[[$that_chunk]]';
                }
                  • 3749
                  • 24,544 Posts
                  Looks good, except that if you want the ID of the parent of the current document, it would be:

                  $modx->resource->get('parent');


                  You could also just use this in the if statements:

                  $output = $modx->getChunk('this_chunk');


                  You don’t need .= and remember to put this at the end or you’ll get nothing:

                  return $output;
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 20014
                    • 200 Posts
                    hoooooray BobRay, that work! smiley
                      • 3749
                      • 24,544 Posts
                      Glad it helped. smiley
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting