Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-09-16 16:35:06

wornout
Member
From: Italy
Registered: 2009-01-20
Posts: 256
Website

[request] Plugin for conditional statement within date or time

My idea is:

<txp:if_date mode="until" day="1" month="5" year="2011">
<txp:else />
</txp:if_date>

It will be perfect for schedule banners visualization or other stuff.
What do you think?

Last edited by wornout (2010-09-16 16:35:30)

Offline

#2 2010-09-16 17:08:36

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: [request] Plugin for conditional statement within date or time

What other values for mode would you allow?

If this can’t be done with articles and expiration, I’d probably prefer the tag having a simple date range:

<txp:if_date start="2010-11-11" end="2010-12-11">

with start and end able to parse a variety of formats (including time of day). Leaving end blank implies no end date, and leaving start blank implies we’re already past the start date.

Additionally could have attributes for days and months, e.g. to allow content to change based on the day of the week or the month. These could be combined with start and end, e.g. to have the tag evaluate true on Tuesday afternoons.


Code is topiary

Offline

#3 2010-09-18 00:40:16

wornout
Member
From: Italy
Registered: 2009-01-20
Posts: 256
Website

Re: [request] Plugin for conditional statement within date or time

I’d like to use two type of mode.
  • between: content will be active only between “from” and “to” date
  • periodic: the content will be active every time the conditions are true
Conditions:
  • days: accepts “su-mo-tu-we-th-fr-sa” pseudo class like :first :last
  • months: same as days

For example if i want to show a banner every monday I write:

<txp:schedule mode="periodic" day="mo" form="banner" />

For example if i want to show a banner every last monday of every months I write

<txp:schedule mode="periodic" day="mo:last" form="banner" />

Leaving month unset means all year.

From and to can be use with periodic mode too. They set the period where other conditions Are checked.

Article expires date are useful but isn’t always articles what you want to show. My suggestion is to use a plugin to schedule everything you want.

Last edited by wornout (2010-09-21 14:41:00)

Offline

#4 2010-11-24 02:03:28

baby
Plugin Author
From: Buenos Aires, Argentina
Registered: 2005-10-16
Posts: 95
Website

Re: [request] Plugin for conditional statement within date or time

OK, here’s an oversimplificated plugin: ort_ifdate

<txp:ort_ifdate>

The ort_ifdate tag is a conditional tag and always used as an opening and closing pair, like this…

<txp:ort_ifdate start=datestring end=datestring>
...conditional statement...
</txp:ort_ifdate>

The tag will execute the contained statements if the current date is between start and end.

Attributes

  • start: start date in the format YYYYMMDD. Conditional will be true from this day on (default is 00010101 or January 1st, of the year 1)
  • end: end date in the format YYYYMMDD. Conditional will be true up to this day (default is 99991231 or December 31st, of the year 9999)
  • dow: day of week a number from 0 (Sunday) to 6 (Saturday) or a string with the name of the weekday (default is none)

Examples

<txp:ort_ifdate start="20690101" end="20691231">
This year we commemorate the first century since man first walked on the Moon
</txp:ort_ifdate>

will print the text only during the year 2069.

Last edited by baby (2011-10-07 18:25:45)


Mariano AbsatzEl Baby

I don’t suffer from insanity. I enjoy every minute of it.

Offline

#5 2010-11-24 07:48:27

wornout
Member
From: Italy
Registered: 2009-01-20
Posts: 256
Website

Re: [request] Plugin for conditional statement within date or time

Thanks!
It will be useful for a lot of purpose! :-)

Offline

#6 2011-10-07 18:28:30

baby
Plugin Author
From: Buenos Aires, Argentina
Registered: 2005-10-16
Posts: 95
Website

Re: [request] Plugin for conditional statement within date or time

At the request of user milosevic I added an extra option dow (day of week). If you use it, it will only execute the statements contained in the tag if it is that day of the week (this is in addition to the start/stop data, that is, the date must fall between start and stop AND be that weekday).

I didn’t test it at all (I’m no longer using or teaching textpattern). Let me know if it works or not.


Mariano AbsatzEl Baby

I don’t suffer from insanity. I enjoy every minute of it.

Offline

#7 2011-10-08 03:22:27

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: [request] Plugin for conditional statement within date or time

This may be useful if_dates

Offline

#8 2011-10-08 08:32:48

milosevic
Member
From: Madrid, Spain
Registered: 2005-09-19
Posts: 390

Re: [request] Plugin for conditional statement within date or time

Great!

Thank you “baby”. I`ll told you when I try it.

and thanks a lot for your superb quick answer.

(Gracias)


<txp:rocks/>

Offline

Board footer

Powered by FluxBB