We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6094
    • 60 Posts
    Is it possible to filter Ditto by time of day?

    I have a project that displays a chunk on the main page. I would like this information filtered based on the time of day. It would need to be a time range. So, it would display information x from 6am to 10am and information y from 10:01am to 3pm, etc.

    I’m really not sure where to start of if this is even possible.

    Thanks in advance for any help you may be able to provide.
      • 1122
      • 209 Posts
      As far as I am concerned it is medium-level exercise in PHx manipulation. The following example displays pagetitles of documents that were created between 20:00:00 and 23:00:00 (no matter which day, month, or year).
      Ditto call:
      [[Ditto? &parents=`1,2,3,4,5` &depth=`1` &display=`all` &tpl=`timeFilter` &dateSource=`createdon` &dateFormat=`%H%M%S`]]
      
      "timeFilter" template:
      [+date:eg=`200000`:then=`[+date:el=`230000`:then=`<p>[+pagetitle+]</p>`:else=``+]`:else=``+]
      
        • 6094
        • 60 Posts
        Thank you very much for your reply. I’m not really a developer so this makes some sense to me, but it’s not 100% clear. I think based on what I need to do I need to switch things some. Hopefully, you or someone else can help shed some light.

        I think based on my application the tpl:
        [+date:eg=`200000`:then=`[+date:el=`230000`:then=`<p>[+pagetitle+]</p>`:else=``+]`:else=``+]

        Would actually need to read something more like this:
        [+date:eg=`startTime`:then=`[+date:el=`endTime`:then=`<p>[+pagetitle+]</p>`:else=``+]`:else=``+]
        startTime and endTime are template variables that store a start time and end time. That probably didn’t need to be said laugh. I’m not sure if that syntax would work or not.

        Next, I believe would require a change to your Ditto call:
        [[Ditto? &parents=`1,2,3,4,5` &depth=`1` &display=`all` &tpl=`timeFilter` &dateSource=`createdon` &dateFormat=`%H%M%S`]]

        I guess dateSource=`createdon` would need to change to the current time. Another area where I’m not exactly sure how to capture this information.

        Any help is greatly appreciated.
          • 3749
          • 24,544 Posts
          Quote from: ctownsend at Nov 13, 2009, 07:27 PM


          Would actually need to read something more like this:
          [+date:eg=`startTime`:then=`[+date:el=`endTime`:then=`<p>[+pagetitle+]</p>`:else=``+]`:else=``+]


          I think something more like this:

          [+date:eg=`[+startTime+]`:and:el=`[+endTime+]`:then=`<p>[+pagetitle+]</p>`:else=``+]`:else=``+]


          That’s assuming that date, startTime and endTime are all in the same format.

            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 6094
            • 60 Posts
            Ok, so here is what I have done to this point. Maybe someone can help put the pieces together.

            I have created a snippet that generates the current time. Then I have a template variable that pulls the snippet value, hence the current time is assigned to the template variable. I then have two template variables that set as start time and end time.

            Basically, if the current time falls between the start and end time I need it to display that pages values within the chunk.

            So, I think the code you have provided may work. Now for my next question. I am using the date widget for the start and end time template variables. This sets the date value to 3:00 pm. So if I am loading the [+startTime+] or [+endTime+] will the code view them in the widget format? I know if it displays to the page it does but I’m not sure if the code is viewed this way.
              • 3749
              • 24,544 Posts
              I don’t know the answer to that last question, but you can always try it and see.

              It might be easier just to have the snippet figure out if the current time is within the limits and just return yes or no.
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting