We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36582
    • 463 Posts
    I'm trying to display different content within a resource according to the day of the week - something like this:

    If today is either Monday, Tuesday, Wednesday, Thursday - show this content (or use this template)

    Else - show some other content (or use another template)

    I haven't got a clue where to start doing this but I came across 'If' http://rtfm.modx.com/extras/revo/if - can anybody tell me how I would achieve that or if there is a better way?

    Thanks in advance
      Web site design in Nottingham UK by Chris Fickling http://www.chrisficklingdesign.co.uk
      • 30912
      • 463 Posts
      AndIf would be better as you are evaluating multiple conditions. I find personally If to be for singular evaluations (thats not to say it cant be used for multiple as it can)

      https://forums.modx.com/thread/?thread=63762&i=1&page=1
      (id copy the URL as its not taking the parameter)

      You would need a way to tell MODx what day it was though

      [[AndIf? &condition=`[[day]] EQ Monday|[[day]] EQ Tuesday` &operator=`OR` &then=`Display Woof` &else=`Display Baa` ]]


      Obviously [[day]] is the snippet to work out the day EQ is the item to set against and 'Monday' is the subject.

      I use AndIf far more than If tbh.

      AndIf will take all of the paramters If does also smiley

      Good Luck
        • 4172
        • 5,888 Posts
        another way:

        create a snippet 'weekday' with this content:

        return date('N');
        


        and create a chunk for each weekday with names like: contentOfDay_1, contentOfDay_2 .....

        install the getCache - package

        and get a cached chunk for each weekday with:
        [[!getCache? 
        &elementClass=`modChunk`
        &element=`contentOfDay_[[!weekday]]`
        ]]
        

          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 36582
          • 463 Posts
          Both really good suggestions thanks you - I will let you know how it turns out.
            Web site design in Nottingham UK by Chris Fickling http://www.chrisficklingdesign.co.uk
            • 30912
            • 463 Posts
            Bruno, I think i'll take a copy of that snippet - very handy.