We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7327
    • 195 Posts
    Hi Guys,

    I’m not sure if this has been tackled before since I don’t know what it’s exactly called. I’m trying to do the following with a ditto call:

    January 2011

    This is story title #1 under January
    This is story title #2 under January
    This is story title #3 under January

    February 2011

    This is story title #1 under February
    This is story title #2 under February

    Now the Under <month> doesn’t mean that the resource stories are filed as children under containers January and February, but rather, I’ve got a section container full of stories inside it. I just want to be able to chronologically group them together by month and having the snippet automatically generate the month-year headers. Is this possible?
      • 7327
      • 195 Posts
      I’ve been playing around with Reflect, and at least it’s got the month-year organization I’m looking for, however, I don’t want the stories generated to be in a different page, but rather, just underneath the month and year heading. Anyone got ideas on how to get this to work in that way?

        • 10449
        • 956 Posts
        All stories (document contents) on the same page? Just include [+content+] in your Ditto tpl.
          • 16278
          • 928 Posts
          I’ve used a PHx modifier that sets and compares a placeholder on each iteration to avoid repeating headings contained in a TV in each individual document. It should be possible to adapt it for a date field, using strftime() to reduce the timestamp to a string for display and comparison.

          The output in my case tabulates players in a band, which will have a number of people sharing the headings Solo Cornet, 2nd cornet, Trombone etc:

          [tt]Solo Cornet Willy Wonka
          Baba Yaga
          2nd Cornet Billy Bunter
          Jane Doe
          Solo Horn Fred Bloggs
          1st Horn Spud Murphy
          Baritone Derek Doofer
          Euphonium Martia Larts
          Trombone I.V. Benson
          Glen Miller
          Eb Bass Val Doonican
          Ivan Rebrov[/tt]

          The Ditto tpl chunk (names are in pagetitle field, position in Tv bwPosition) looks like this:
          <tr><th>[+bwPosition:repeat=`[+lastPosition+]`+]</th> <td>[+pagetitle+]`+]</td></tr>

          The PHx modifier, called phx:repeat:
          <?php
          // phx:repeat
          if ($output == $options) {
          	$result = ' ';
          } else {
          	$result = $output;
          }
          $modx->setPlaceholder('lastPosition', $output);
          
          return $result;
          ?>


          laugh KP
            • 7327
            • 195 Posts
            @Ganesh - I think I’m looking for something closer to what KP posted.

            @KP - Hmm so the first step is to chronologically assemble a ditto call either in an ascending or descending manner. Then I’ve to compare the published date with... what exactly... Unless there’s a way for me to take the date from a Reflect snippet placeholder and compare it against that.

            Is a unix timestamp the only way to easily compare dates against dates?
              • 16278
              • 928 Posts
              There’s no need for more than one Ditto call, or for Reflect at all. The idea is that each item contains the data you need for the heading, but you suppress the heading if it is the same as the one printed immediately before it. The placeholder simply carries the current item’s data for the comparison next time the chunk is called on by Ditto.

              So you’d have the relevant date field where my bwPosition TV is. The PHx modifier will have to work a little harder, formatting the date into a string with the heading tag, comparing it with the placeholder set by the previous item, producing the new heading if different or null value if the same, and setting the value of the placeholder to the current item’s heading tag for comparison when the next item is generated by Ditto.

              I’ll flesh this out with an example if I can, but that won’t be before Sunday, according to my "computer-free Saturday" New Year resolution.
              smiley KP
                • 7327
                • 195 Posts
                Hey, I tried out your suggestion and it worked! Here’s the code I used:

                DITTO CALL

                [!Ditto?parent=`8` &extenders=`dateFilter` &id=`archive` &dateSource=`pub_date` &tpl=`gallery_archive_list` &orderBy=`pub_date DESC` !]



                DITTO TPL CHUNK
                <span>[+date:archiveheaders=`[+archiveHeader+]`+]</span>
                <p>[+pagetitle+]</p>


                PHX MODIFIER CODE
                $timestamp = strtotime($output);
                $timestamp2 = strtotime($options);
                
                $result = strftime("%B, %Y", $timestamp);
                $result2 = strftime("%B, %Y", $timestamp2);
                
                
                if ($result == $result2) {
                $result = '';
                } else {
                }
                $modx->setPlaceholder('archiveHeader', $output);
                
                return $result;
                


                I completely forgot about the built-in PHP functions. But I did what you suggested - convert them to time stamps and back to the date format I needed, and proceed with the comparison. I’ll have to modify the chunk so it doesn’t ouput blank spans or whatever tags... But thanks a bunch for the tip bro!

                Cheers,
                Les