We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34017
    • 898 Posts
    that is a neat little trick. have i said modx rocks today?

    modx rocks! (now i have)
      Chuck the Trukk
      ProWebscape.com :: Nashville-WebDesign.com
      - - - - - - - -
      What are TV's? Here's some info below.
      http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
      http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008
      • 21257 MODX Staff
      • 730 Posts
      Just looking at this again, and I think I steered you incorrectly.
      Figuring something out - I’ll post again shortly.
        Mike Schell
        Lead Developer, MODX Cloud
        Email: [email protected]
        GitHub: https://github.com/netProphET/
        Twitter: @mkschell
        • 21257 MODX Staff
        • 730 Posts
        Ok, my apologies - my idea was close but flawed.

        Making a chunk call right in the snippet parameters can be useful, but in this case, the chunk you’re calling is going to inherit the template variables of the homepage, not the page that Ditto is grabbing for you.

        So back to referring to a Chunk by name in the Ditto call...
        [[Ditto? &tpl=`frontpagefigure-outer` ... ]]
        


        Then Ditto will call that Chunk in the context of the page (article) it’s ditto-ing for you.
        The Chunk can stay basically the same, except that

        • the custom snippet’s name will now be confusing so I’m renaming it
        • we have access to the template variables of the ditto’d document with Ditto’s convention [+tvWhatever+]
        [[FrontPageTemplate? &Graph-image=`[+tvGraph-image+]` &Graph-datasource=`[+tvGraph-datasource+]` &Photo=`[+tvPhoto+]` &Mug3=`[+tvMug3+]` &Mug-caption3=`[+tvMug-caption3+]` &Mug2=`[+tvMug2+]` &Mug-caption2=`[+tvMug-caption2+]` &Mug=`[+tvMug+]` &Mug-caption=`[+tvMug-caption+]` &pullquote=`[+tvpullquote+]` ]]
        


        Now we finally have a snippet being called and it will have access to all of the variables that you want it to.
        The snippet is going to change - instead of returning the name of the chunk you decide is best based on the variables in the article, we’ll return the chunk itself. And, because I’m not sure whether Ditto, PHx or the MODx parser itself would end up doing the placeholder replacement on the final template chunk, we’ll do that ourselves in the snippet.

        <?php
        
        // array of values for replacing in whatever homepage template chunk
        $aReplacements = array(
            'Graph-image' => $Graph-image,
            'Graph-datasource' => $Graph-datasource,
            'Photo' => $Photo,
            'Mug3' => $Mug3,
            'Mug-caption3' => $Mug-caption3,
            'Mug2' => $Mug2,
            'Mug-caption2' => $Mug-caption2,
            'Mug' => $Mug,
            'Mug-caption' => $Mug-caption,
            'pullquote' => $pullquote
        );
        
        $chunkToReturn = '';
        // the following logic is bogus - just means to show how you can now access the articles tvs in php to craft the logic
        if( $Graph-image != '' && $Mug2 == '' ) {
            $chunkToReturn = 'chunk1';
        } elseif( $Graph-image == '' && $pullquote != '' ) {
            $chunkToReturn = 'chunk1';
        }
        
        return $modx->parseChunk($chunkToReturn, $aReplacements, '[+', '+]');
        


        That last line simultaneously parses the chunk and returns it.
        In your 6 end chunk templates, you can use the placeholder syntax [+somePlaceholder+] (that’s what the last 2 parameters of the parseChunk method are setting)

        I hope this works. tongue
          Mike Schell
          Lead Developer, MODX Cloud
          Email: [email protected]
          GitHub: https://github.com/netProphET/
          Twitter: @mkschell
          • 7111
          • 30 Posts
          Sorry it’s been so long. I’ve just been so busy. I finally got a chance to work on this today, and I’m pleased to report that so far this is working quite well. I have not used this snippet/chunk in a live environment yet, I’m still testing this locally on my machine.

          I’m also working on reducing the total number of tv’s that I have to use per document, reducing them to a more manageable amount, and I also got phpThumb working today.

          If I can make it so that I can update this site every week in less than 2 hours, I’ll be happy. smiley

          I’ll keep you posted. Thanks for the help netProphET!