We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28528
    • 31 Posts
    Hi, I’m just trying to build my first MODx site and after spending several days finding my way around I’m really impressed with it smiley

    The site I’m building is for a rugby club. I’ve set up a number of containers holding the various pages for the 1st team, 2nd team, junior teams etc etc. Now I would like to diplay a different chunk of content in the right sidebar depending on which parent container the page belongs to. I’ll try to explain... For example when a user is viewing the 1st team pages the sidebar would display a chunk containing a simple html table of the 1st team’s match results. And in the 2nd team pages the sidebar would show the 2nd team results table and so on.

    I’m hoping it is just a php query I need but I’ve no idea where to even start. Hopefully someone can point me in the right direction.

    Many thanks.

      • 3749
      • 24,544 Posts
      Even simpler than a query. I would put the various tables in chunks and use a snippet that uses getParent() and getChunk() (although you could also do it with a template variable that selected the chunk). I’m assuming that you’re using Evolution (this would look a little different in Revolution).

      Here’s the snippet call:

      [!GetSidebar? pageId = `[*id*]` !]


      and the snippet (more or less):

      <?php
      
      /* get parent id */
      $pid = $modx->getParent($pageId);
      
      switch ($pid) {
      
          case '1':
              return $modx->getChunk('chunk1');
              break;
          case '2':
              return $modx->getChunk('chunk1');
          break;
      }
      
      return $modx->getChunk('defaultChunk');
        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
        • 28528
        • 31 Posts
        Wow, thanks for the superfast help!

        I’m trying to get it to work but I’m getting an error where the chunks should be showing in the sidebar:

        Parse error: syntax error, unexpected T_VARIABLE, expecting ’(’ in /home/kidwelly/public_html/manager/includes/document.parser.class.inc.php(770) : eval()’d code on line 4

        Here’s my code:

        <?php
        $pid = $modx->getParent($id);
        
        switch $pid {
        
           case '1':
            return $modx->getChunk('firsts-league');
            break;
           case '2':
            return $modx->getChunk('chunk1');
            break;
        }
        
        return $modx->getChunk('firsts-league');
        ?>


        I have a chunk named ’firsts-league’ which includes a simple html table
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          It means exactly what it says; on line 4, after the switch keyword it expects a (
          switch ($pid) {

          http://us3.php.net/manual/en/control-structures.switch.php
            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
            • 3749
            • 24,544 Posts
            Sorry, I was dashing that off as my dinner got cold.

            Fixed in the 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
              • 28528
              • 31 Posts
              Thanks to you both, I think I’m getting the hang of this now.

              The only thing is that only the default chunk is showing regardless of the parent id

              <?php
              $pid = $modx->getParent($id);
              
              switch ($pid) {
              
                 case '15':
                  return $modx->getChunk('firsts-league');
                  break;
                 case '67':
                  return $modx->getChunk('seconds-league');
                  break;
              }
              
              return $modx->getChunk('firsts-league');
              ?>
              
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                Where is that $id variable coming from?
                $pid = $modx->getParent($id);
                  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 not sure. Is it anything to do with..

                  [!GetSidebar? pageId = `[*id*]` !]


                  Sorry, I feel such a noob!

                  Steve
                    • 20413
                    • 2,877 Posts
                    Use
                    $pid = $modx->getParent($pageId);
                    in the snippet
                    and
                    [!GetSidebar?pageId=`[*id*]`!] or [!GetSidebar? &pageId=`[*id*]`!]
                    as snippet call
                      @hawproductions | http://mrhaw.com/

                      Infograph: MODX Advanced Install in 7 steps:
                      http://forums.modx.com/thread/96954/infograph-modx-advanced-install-in-7-steps

                      Recap: Portland, OR (PDX) MODX CMS Meetup, Oct 6, 2015. US Bancorp Tower
                      http://mrhaw.com/modx_portland_oregon_pdx_modx_cms_meetup_oct_2015_us_bancorp_tower
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      Get rid of those spaces in the &pageId=`[*id*]` parameter.
                        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