We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7455
    • 2,204 Posts
    I was struggling with the fact that the parser can not pars a snippet insite a chunk call, e.g. {{chunkname-[[snippetname]]}}.
    You may ask why would you want to do somthing like that? Here is why:

    I often make multilangual sites and to show the visitor on what language he is I use flags those flags also have a link to the other languages.
    so using a snippet like UltimateParent inste a chunk call would give me the option to get ID specific chunk calls like this {{flags-[[UltimateParent]], this than generates a chunk call like this {{flags-12}} (if the ultimateParent is 12 for that language)  but as I sayd befor this does not work.

    Now I’v adapted Susan’s great Script (UlimateParent) to ouput a chunk call based on the UltimateParent ID:

    Just call the snippet like this:
    [!GetChunkByUPID? &chunk=`chunkprefix-`!]
    and create the coresponding chunks e.g. chunkprefix-12 

    when you do not set the $chunk in the snippet call or in the snippet itself it will return a chunkname that only contains a ID e.g. {{12}}

    this way you can display chunks that correspond to UltimateParents ID without using a TV and @INHERIT

    // GetChunkByUPID - MODx snippet (Get Chunk by UltimateParent ID)
    // recursively searches the document tree
    // and determines the "ultimate" parent
    // (the one whose parent is 0)
    // of the given document, then ads that ID to a chunk name.
    // it will then give you a chunk call corresponding to the id
    // e.g. if $chunk is "flags-" and the id that is found is "12" it will give you a chunk call : {{flags-12}} 
    // this way you can display chunks that correspond to UltimateParents ID without using a TV and @inherit
    //
    // created 02 Nov 2005 by [email protected]
    // adapted 19 June 2006 by [email protected]
    //
    // released to the public domain
    // 
    //
    //
    //settings:
    //set the chunk prefix eg "flags-" here or 
    //use it in the call like this:  [!GetChunkByUPID? &chunk=`chunkprefix`!] 
    //
    $chunk = (isset($chunk))? $chunk : "";
    //
    //The rest will take care of it self
    //
    $id = $modx->documentIdentifier;
    $pid = $modx->getParent($id,1,"id");
    if($pid['id'] == 0) { return $id; }
    while ($pid['id'] != 0) {
        $id = $pid['id'];
        $pid = $modx->getParent($id,1,"id");
    }
    $output= "{{".$chunk.$id."}}";
    
    return $output;
    


    Greets Dimmy
      follow me on twitter: @dimmy01
      • 32963
      • 1,732 Posts
      HiDimmy,

      Very nice snippet. I believe MODx 1.0 and behond will allow for such nested tags.

      Hint: I’m working on a similar parser at the moment. Going back to work on it now.
        xWisdom
        www.xwisdomhtml.com
        The fear of the Lord is the beginning of wisdom:
        MODx Co-Founder - Create and do more with less.
        • 23171
        • 4 Posts
        Hello,

        Thanks for this snppet, but I encounter a problem using it.

        It works fine for all levels below the ultimate parent, but when I’m on the ultimate parent, it returns the ultimate parent id (in text, like 7in my case) and doesn’t seem to use the chunk-x.

        I use it with wayfinder to make a menu with 2 different parents in 2 of my 4 menus in my main menu.

        The snippet call :

        [!GetChunkByUPID? &chunk=`Menu2-`!]


        My "Menu2-7" chunk :

        [!Wayfinder? &startId=`38` &level=`1` &outerTpl=`Menu22outerTpl`!][!Wayfinder? &startId=`7` &level=`1` &outerTpl=`Menu2outerTpl`!]


        Thanks for any help smiley
          • 7455
          • 2,204 Posts
          it should aways return the chuck see:
          $output= "{{".$chunk.$id."}}";

          so it wil aways give you this {{chunkname-id}}
          I used this snippet myself a lot.

          Is your page cached maybe? even so it should still work.
          I will test this later to see if I can recreate your findings.
            follow me on twitter: @dimmy01
            • 23171
            • 4 Posts
            Hey,

            Thx for the answer. I’ll try today or tomorrow without caching the page and tell you what happen.