We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    That code should default to $modx->documentIdentifier if $pageId is not set.
    <?php
    $pageId = isset($pageId) ? $pageId : $modx->documentIdentifier;
    $pid = $modx->getParent($pageId);
    
    switch ($pid) {
    
       case '15':
        return $modx->getChunk('firsts-league');
        break;
       case '67':
        return $modx->getChunk('seconds-league');
        break;
    }
    
    return $modx->getChunk('firsts-league');
    ?>
      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
      • 28528
      • 31 Posts
      I’m really sorry, this is sure to be something stupid that I’m doing but it still isn’t working.
      Every page is still showing the same content in the sidebar.

      It might help if I describe what I’ve done just in case I missed a step that’s obvious to you but not me.

      So, I’ve started by adding the following into my template
      <div id="sidebar"> !GetSidebar?&pageId=`[*id*]`!] </div>          


      Then I added a snippet named GetSidebar:
      <?php
      $pageId = isset($pageId) ? $pageId : $modx->documentIdentifier;
      $pid = $modx->getParent($pageId);
      
      switch ($pid) {
      
         case '15':
          return $modx->getChunk('firsts-league');
          break;
         case '67':
          return $modx->getChunk('seconds-league');
          break;
      }
      
      return $modx->getChunk('firsts-league');
      ?>


      And that’s it. Should I have done anything else?



        • 26931
        • 2,314 Posts
        Hi stevechilvers,

        <div id="sidebar">[!GetSidebar? &pageId=`[*id*]`!]</div> 


        you forgot [
          • 28528
          • 31 Posts
          Hi sharkbait,

          Thanks but that was a just typo in this post the bracket was there in the live code.

          Still not working :-(
            • 16183
            • 1,390 Posts
            @steve,

            Hmmm, if this is not a local site, you could probably create a temporary user and PM one of these gurus the login details to have a look...assuming they are willing to wink

            Sorry about your troubles.

            cheers/k
              • 3749
              • 24,544 Posts
              I’m not sure it matters, but put a space after the ? in the snippet call.

              Check the spelling of pageId and pid everywhere they appear (including the snippet tag) -- they’re case-sensitive.

              If that doesn’t do it, let’s put some diagnostics into the snippet:

              <?php
              $output = '<br>In Snippet<br>';
              
              $pageId = isset($pageId) ? $pageId : $modx->documentIdentifier;
              $ouput .= '<br>pageId: ' . $pageId;
              
              $pid = $modx->getParent($pageId);
              $output .= '<br>Parent ID: ' . $pid . '<br>';
              
              switch ($pid) {
              
                 case '15':
                  $output .= $modx->getChunk('firsts-league');
                  break;
              
                 case '67':
                  $output .= $modx->getChunk('seconds-league');
                  break;
              
                 default:
                  $output .= 'Not Found';
              }
              
                 $output .= '<br'>
              return $output;
              ?>


              See what that produces.
                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
                • 22840
                • 1,572 Posts
                Not sure if it would make a difference but are the pages your doing this on cached ??

                If so edit the pages and take the tick out of cacheable and clear the site cache.
                  • 3749
                  • 24,544 Posts
                  Quote from: paulp at Aug 25, 2009, 06:45 PM

                  Not sure if it would make a difference but are the pages your doing this on cached ??

                  If so edit the pages and take the tick out of cacheable and clear the site cache.

                  Since the snippet is uncached, I think the pages should be cached. It’s my understanding that in Evo, an uncached snippet in an uncached page becomes cached, but I could have it wrong.
                    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
                    • 22840
                    • 1,572 Posts
                    Quote from: BobRay at Aug 25, 2009, 06:58 PM

                    Quote from: paulp at Aug 25, 2009, 06:45 PM

                    Not sure if it would make a difference but are the pages your doing this on cached ??

                    If so edit the pages and take the tick out of cacheable and clear the site cache.

                    Since the snippet is uncached, I think the pages should be cached. It’s my understanding that in Evo, an uncached snippet in an uncached page becomes cached, but I could have it wrong.

                    That’s weird lol

                    2 un cached making a cached, bit like 2 wrongs not making a right laugh

                    Learn something new every day lol
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      If the document is uncached, nothing is cached. An uncached snippet call simply has its tags converted to cached tags [[...]] and then in the post-processing if a snippet is found the document is sent through the parser again so that the snippet gets processed.

                      This is also what happens in a cached document; the uncached snippet tags are changed to normal tags, the page is cached, then post-processing sees the snippet tags and runs the page through the parser again to process the snippet.

                      Likewise when the page is taken from cache, the post-processing sees the snippet tags and sends the document through the parser to process the snippet.
                        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