We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14050
    • 788 Posts
    I tried searching, and I couldn’t come up with anything, so if this has been addressed already, please let me know. What I was wondering is if I could get Ditto to template each summary post by grabbing the chunk name from a TV stored within the perspective document.

    For example:

    Parent Folder
    Document A - > TV: Bluebox -> Chunk named Bluebox is used as template for Summary of Document A.
    Document B - > TV: Redbox -> Chunk named Redbox is used as template for Summary of Document B.
    Document C - > TV: Bluebox -> Chunk named Bluebox is used as template for Summary of Document C.
    Document D - > TV: Greenbox-> Chunk named Greenbox is used as template for Summary of Document D.

    Now I know that Ditto allows for a first, last, even, and odd templating. However, I would like the document to hold the appropriate chunk name in a TV, and be able to determine how its summary should be templated.
      Jesse R.
      Consider trying something new and extraordinary.
      Illinois Wine

      Have you considered donating to MODx lately?
      Donate now. Every contribution helps.
      • 33337
      • 3,975 Posts
      Hi Jesse,

      Conditional templating is not possible in Ditto/MODx right now, but it seem that you can yield the desired results with Ditto 1.1 beta2 + PHx http://wiki.modxcms.com/index.php/PHx (though I didn’t play with it myself yet)

      Hope this helps.

      regards,

      zi
        Zaigham R - MODX Professional | Skype | Email | Twitter

        Digging the interwebs for #MODX gems and bringing it to you. modx.link
        • 14050
        • 788 Posts
        The more and more I play with MODx and PHP, the more I find myself able to do. So I figured that ditto should have this capability, but it doesn’t seem to. Well I hacked it into ditto. I think this makes ditto infinitely more customizable with templates.

        What this hack basically does, is allow the document being summarized by ditto to control the template of that summary. As such, you could have an infinite number of templates in ditto now. This is what you have to hack, to allow this.

        First in the ditto snippet locate the comment that says "Process information for display." and change:

        $output .= $ditto->render($resource[$x], $x, $format, $dateFormatType, $templates, $dateFormat, $debug, $summary, $link, $stop); 


        TO

        $output .= $ditto->render($resource[$x], $x, $format, $dateFormatType, $templates, $dateFormat, $debug, $summary, $link, $stop,$tplTV); 


        In the ditto.class.inc.php file at around line 166 change:

        function render(&$resource, $x, $format, $datetype, $templates, $date, $debug, $summary = "", $link = "", $stop)


        TO

        function render(&$resource, $x, $format, $datetype, $templates, $date, $debug, $summary = "", $link = "", $stop,$tplTV)


        In the ditto.class.inc.php file at around line 214 change:

        $currentTPLKey = $this->getCurrentTPL($x, $stop, $resource['id'], $format, $templates);
        $currentTPL = $templates["$currentTPLKey"];
        $currentTPLname = substr("$currentTPLKey", 3);


        TO

        $currentTPLKey = $this->getCurrentTPL($x, $stop, $resource['id'], $format, $templates);
        $currentTPL = $templates["$currentTPLKey"];
        $currentTPLname = substr("$currentTPLKey", 3);
        $currentTPLByChunk = $modx->getTemplateVar($tplTV,$fields="*",$resource['id']);
        if($modx->getChunk($currentTPLByChunk['value'])) $currentTPL = $modx->getChunk($currentTPLByChunk['value']);


        THAT IS IT!

        Now just create a template variable in the document that you want to be able to the template for its ditto summary. In that template variable, put the name of the chunk that contains the ditto placeholders.

        Example Call with New Parameter:

        [!Ditto? &startID=`2` &summarize=`5` &total=`9` &tpl=`m3_ContentUnit` &tplTV=`tplOverride`!]

        Now let’s say I place 7 documents in a folder and their template has the TV called tplOverride.

        Doc 1 set tplOverride to RedBox
        Doc 2 set tplOverride to OrangeBox
        Doc 3 set tplOverride to YellowBox
        Doc 4 set tplOverride to GreenBox
        Doc 5 set tplOverride to BlueBox
        Doc 6 set tplOverride to IndigoBox
        Doc 7 set tplOverride to VioletBox

        Now instead of using the chunk m3_ContentUnit, each document will use its respective chunk (i.e. RedBox, OrangeBox,etc.) If one of those chunks doesn’t exist, then Ditto will fall back to the default template I set, m3_ContentUnit.

        WARNING! I just quickly tested this. It might cause some problems outside of my limited testing. If it does, let me know. Also, I am sure there is a more eloquent solution, so feel free to show me how I can be more eloquent of a coder.
          Jesse R.
          Consider trying something new and extraordinary.
          Illinois Wine

          Have you considered donating to MODx lately?
          Donate now. Every contribution helps.
          • 33337
          • 3,975 Posts
          Hi Jesse,

          your solution seems to be good and IMO gives more extensibility to Ditto, but which Ditto code you used? Just to let you know that there is Ditto 1.1 Beta2 which is going to be re-factored with new features such as more flexible templating AFAIK, http://modxcms.com/forums/index.php/topic,8988.0.html

          regards.
            Zaigham R - MODX Professional | Skype | Email | Twitter

            Digging the interwebs for #MODX gems and bringing it to you. modx.link
            • 18397
            • 3,250 Posts
            Jesse, clever idea! I had planned on adding similar functionality to Ditto 1.1 using a differant approach but hopefully I can merge both implimentations into one that is both fast and efficient. I hope to have conditional templates into the next major release so that instead of first, alt, last, or current document templates. This way, you could say, if tv cheese is equal to 4 then use template x. If it is the last document, make it template y, etc. Its like filtering, but for templates!


            For those that can’t wait for Beta 3, there is an important thing to note about Jesse’s hack. By calling $modx->getTemplateVar (should be getTemplateVarOutput if you have a TV that has a widget attached) you add an additional SQL query for each document retrieved. This can add up quickly if you have more than a hundred documents.
              • 14050
              • 788 Posts
              Zi,

              I am using DItto 1.1Beta2 and I looked at your suggestion of using PHx, but it just seemed easier for me to hack ditto then use PHx, if in fact that would have worked.

              Mark,

              Yeah I figured such an idea had to be on the roadmap for Ditto. Nice catch about the the inefficiencies. By no means did I think this was the best or even a good implementation of the idea. I just figured if I created the proof-of-concept, and people felt that it was a worthwhile feature, that you would take the reins and do it properly.

              Jesse
                Jesse R.
                Consider trying something new and extraordinary.
                Illinois Wine

                Have you considered donating to MODx lately?
                Donate now. Every contribution helps.
                • 14050
                • 788 Posts
                Just so everyone can see the power of this. I am working on templating Multiflex-3 here:

                http://www.fredsbarn.com/sandbox/MODx2008/index.php?id=1

                Look at the boxes on the right.

                All the boxes are stored inside a parent folder. Then in the template I do a ditto call in the appropriate area. Now I can have as many boxes as I want. Plus I can get crazy complex and use filtering by TV and SortBy using TV’s to allow for complete control. Now with my boxes all stored in one location, I can just place the same call in the different template layouts to place the boxes.

                I think this makes life pretty easy.
                  Jesse R.
                  Consider trying something new and extraordinary.
                  Illinois Wine

                  Have you considered donating to MODx lately?
                  Donate now. Every contribution helps.
                  • 18397
                  • 3,250 Posts
                  I am thinking the syntax for the tpl conditional, and all filters for that matter, should be done in a more human readable fashion like the following. No more silly number represents a sign (since the parser can’t handle <>=! etc in the snippet parameter). It may take a little more time to parse but makes ooooh so much more sense.

                  &tpl=`tplChunkName1 if x is n, name2 if y is not n, name3 if [last,first,alt] document`.

                  Where less than and greater than are also possible.

                  Also, the variable detection routine would detect the following @bindings:

                  @TV:cheese uses the TV cheese’s value

                  @DOC:content uses the content variable content
                    • 14050
                    • 788 Posts
                    Quote from: Mark at Nov 16, 2006, 02:13 AM

                    Jesse, clever idea! I had planned on adding similar functionality to Ditto 1.1 using a differant approach but hopefully I can merge both implimentations into one that is both fast and efficient. I hope to have conditional templates into the next major release so that instead of first, alt, last, or current document templates. This way, you could say, if tv cheese is equal to 4 then use template x. If it is the last document, make it template y, etc. Its like filtering, but for templates!


                    For those that can’t wait for Beta 3, there is an important thing to note about Jesse’s hack. By calling $modx->getTemplateVar (should be getTemplateVarOutput if you have a TV that has a widget attached) you add an additional SQL query for each document retrieved. This can add up quickly if you have more than a hundred documents.


                    Mark,

                    Did this ever get implemented? Or is this still on the roadmap for Beta 3?

                    Jesse
                      Jesse R.
                      Consider trying something new and extraordinary.
                      Illinois Wine

                      Have you considered donating to MODx lately?
                      Donate now. Every contribution helps.
                      • 18397
                      • 3,250 Posts
                      It is still on the roadmap for the next major release. With my Winter Break starting tomorrow afternoon I have 3 weeks to spend on Ditto smiley