We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9995
    • 1,613 Posts
    fourroses666 Reply #1, 14 years ago

    This is what I like to do:


    Show chunk A when i'm on the page main1 or subpage or subsubpage of main1
    Show chunk B when i'm on main2 or subpage or subsubpage of main2
    Else show chunk 3

    Is there a way to use PHx for this or other solution?


    Site structure:

    main1
    | - sub1
    | -- subsub1
    | -- subsub2
    | - sub2

    main2
    | - sub1
    | -- subsub1
    | -- subsub2
    | -- subsub3
    | - sub2
    | -- subsub1
    | -- subsub2
    etc.

    [ed. note: fourroses666 last edited this post 14 years ago.]
      Evolution user, I like the back-end speed and simplicity smiley
      • 4041
      • 788 Posts
      Try this snippet and see if it helps (it will probably need to be called uncached):

      newest code source found here:
      https://forums.modx.com/thread/79398/ditto-parent-parent#dis-post-476315 [ed. note: breezer last edited this post 13 years, 1 month ago.]
        xforum
        http://frsbuilders.net (under construction) forum for evolution
        • 9995
        • 1,613 Posts
        fourroses666 Reply #3, 14 years ago
        Thankz allot Beezer!

        looks really great :-D
          Evolution user, I like the back-end speed and simplicity smiley
          • 4041
          • 788 Posts
          newest code source found here:
          https://forums.modx.com/thread/79398/ditto-parent-parent#dis-post-476315 [ed. note: breezer last edited this post 13 years, 1 month ago.]
            xforum
            http://frsbuilders.net (under construction) forum for evolution
            • 9995
            • 1,613 Posts
            fourroses666 Reply #5, 14 years ago
            That looks even better m8, very handy smiley
            I'm too sick to test atm.
              Evolution user, I like the back-end speed and simplicity smiley
              • 9995
              • 1,613 Posts
              fourroses666 Reply #6, 14 years ago
              I have just tested it and can confirm it works as a charm, thanks again for your time to post the script breezer.

              [ed. note: fourroses666 last edited this post 14 years ago.]
                Evolution user, I like the back-end speed and simplicity smiley
                • 4041
                • 788 Posts
                Glad it works and you're very welcome smiley
                  xforum
                  http://frsbuilders.net (under construction) forum for evolution
                  • 9995
                  • 1,613 Posts
                  Glad I found this again, it's such a nice snippet, should be in the new repository called Store. https://forums.modx.com/thread/86066/first-repository-for-modx-evolution

                  dmi3y? :0
                    Evolution user, I like the back-end speed and simplicity smiley
                    • 4041
                    • 788 Posts
                    :) Here is a newer version:
                    <?php
                    /* hierarchy_based_chunk
                    
                    [!hierarchy_based_chunk?
                        &ids_chunks=`2|hbc_1 , 21|hbc_2`
                        &def_chunk=`hbc_def`
                    !]
                    
                    the above snippet call in a template produces:
                    hbc_1 chunk on doc 2 and all children/grandchildren
                    hbc_2 chunk on doc 21 and all its children/grandchildren
                    hbc_def chunk on all other documents
                    
                    */
                    
                    //$xstart = $modx->getMicroTime();
                    
                    // set default parent id | chunk name
                    // ex:  $default_ids_chunks = array( '2|hbc_1' , '21|hbc_2' );
                    $default_ids_chunks = array();
                    
                    // set an overall default chunk name
                    $default_chunk = isset( $def_chunk ) ? $def_chunk : '';
                    
                    
                    $output ='';
                    $print_chunk ='';
                    
                    $parts = $ids_chunks !='' ? explode( ',', $ids_chunks ) : $default_ids_chunks;
                    
                    if( !empty( $parts ) ){
                    
                        $uparent = $modx->runSnippet( 'UltimateParent' );
                    
                        $check_array = array( $modx->documentObject['id'], $uparent );
                    
                        foreach( $parts as $k => $v ){
                        
                            $xplod = explode( '|', $v );
                            
                            // id
                            $x = trim( $xplod[0] );
                            
                            // chunk name
                            $y = trim( $xplod[1] );
                            
                            if( in_array( intval( $x ), $check_array ) && $print_chunk =='' ){
                    
                                $print_chunk = $y;
                    
                            }
                        }
                    }
                    
                    // if $print_chunk is empty set to overall default
                    if( $print_chunk =='' ){
                    
                        $print_chunk = $default_chunk;
                    
                    }
                    
                    $output .= $modx->getChunk( $print_chunk );
                    
                    //$xend = $modx->getMicroTime();
                    //$output .='<p>'.( str_replace( '-', '', sprintf( "%2.4f s", $xstart - $xend ) ) ).'</p>';
                    
                    return $output;
                    ?>
                      xforum
                      http://frsbuilders.net (under construction) forum for evolution
                      • 9995
                      • 1,613 Posts
                      Nice, when calling a chunk with a wayfinder call into it you need to play with cached or uncached but besides that it's good!

                      Is there any way to get a ditto call working into it?
                      It just posts the call instead it gets processed [[Ditto? ...]]

                      I remember you had a solution like adding the ditto into the snippet some way?

                      // set up the ditto snippet params
                      $ditto_params = array(
                          'parents'                  => '5',
                          'total'                    => '99',
                          'showPublishedOnly'        => '1',
                          'orderBy'                  => 'menuindex ASC',
                          'tpl'                      => 'detail',
                          'tplCurrentDocument'       => '@CODE:'.$detail_actief
                      );
                      [ed. note: fourroses666 last edited this post 13 years, 1 month ago.]
                        Evolution user, I like the back-end speed and simplicity smiley