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
    Can anyone see why this snippet stopped working?
    After update to 1.0.14 I see the message: "No documents found"

    Is it because of an update of ditto/ultimateparent or smt?

    <?php
    /* hierarchy_based_chunk
     
    [!banner?
        &parent_ids=`1,2,3`
        &chunk_names=`banner_chunk1,banner_chunk2,banner_chunk3`
        &def_chunk_name=`banner_main`
    !]
     
    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
     
    */
    // set the default ids of the top level parent containers
    $default_parent_ids = array();
     
    // set the default names of the chunks to display
    // based on the same order as the $parent_ids
    $default_chunk_names = array();
     
    // set the overall default chunk name
    $default_chunk_name = isset($def_chunk_name) ? $def_chunk_name : '';
     
    // ===== end setup ===== //
     
     
    $parent_ids = isset($parent_ids) ? explode(',',$parent_ids) : $default_parent_ids;
    $chunk_names = isset($chunk_names) ? explode(',',$chunk_names) : $default_chunk_names;
     
    if(count($parent_ids) > 0 && count($chunk_names) > 0){
     
        $uparent = $modx->runSnippet('UltimateParent');
        $check_array = array($modx->documentObject['id'],$modx->documentObject['parent'],$uparent);
     
        for($x=0; $x < count($parent_ids); $x++){
            if(in_array($parent_ids[$x],$check_array)){
                $print_chunk = $chunk_names[$x];
            }
        }
         
        // if $print_chunk is empty set to overall default
        if($print_chunk ==''){
            $print_chunk = $default_chunk_name;
        }
         
    }
     
    return $modx->getChunk($print_chunk);
    ?>
    

    [ed. note: fourroses666 last edited this post 12 years, 3 months ago.]
      Evolution user, I like the back-end speed and simplicity smiley
      • 1343 ☆ A M B ☆
      • 2,213 Posts
      What version of Evolution did you upgrade from?
        Patrick | Server Wrangler
        About Me: Website | Tweets |  MODX Hosting
        • 9995
        • 1,613 Posts
        Hmm, I'm not sure, I think 1.0.8.

        after next week I can see what it was, at the office this is written down but I'm on vacation now shocked


          Evolution user, I like the back-end speed and simplicity smiley
          • 13428 ☆ A M B ☆
          • 1,031 Posts
          I don't see anything problematic in the snippet code. Maybe you could explicit cast every content of $check_array to string.

          $check_array = array((string)$modx->documentObject['id'],(string)$modx->documentObject['parent'],(string)$uparent);


          You could also look in the snippet call. Maybe there are some unusual tags in there now – if you are using TinyMCE on that resource and have called the snippet in document content. [ed. note: Jako last edited this post 12 years, 3 months ago.]
            • 9995
            • 1,613 Posts
            hmm, log is empty, call is in a chunk, the array gives the same result, normal dittocall works.

            i have no idea whats going on.
              Evolution user, I like the back-end speed and simplicity smiley
              • 13428 ☆ A M B ☆
              • 1,031 Posts
              But your snippet above does not have any Ditto snippet call inside. It just returns the chunk content of banner_chunk1 for current resource UltimateParent equal 1, chunk content of banner_chunk2 for current resource UltimateParent equal 2, chunk content of banner_chunk3 for current resource UltimateParent equal 3 and chunk content of banner_main for all other resources (with the default snippet call in the snippet code).

              Is the hierarchy_based_chunk snippet called in a Ditto template? Then you should add a parameter i.e. &docid to hierarchy_based_chunk snippet and call UltimateParent in the snippet with that docid.

              $uparent = $modx->runSnippet('UltimateParent', array('id' = $docid));
                • 4041
                • 788 Posts
                I agree with trying the solution presented by jacko, back when this snippet was created ultimateparent always defaulted to current document and somewhere along the line it changed.
                  xforum
                  http://frsbuilders.net (under construction) forum for evolution