Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#301 2009-06-02 03:48:45
Re: smd_calendar: complete schedule / event / calendar / diary
Hi!
Just chimed in to post a few comments or loose ideas:
About re-creating the small calendar using the large one + cellform
. Well, the important part is the cellform
, of course.
Be prepared to read some ugly code… because while trying to recreate the small calendar (a fairly easy task for this wonderful plugin) I noticed that the necessary replacement variables were missing.
{day}
and {month}
return single digits for day or month <=
9.
So I wasn’t able to recreate the URL variable ?month=YYYY-MM-DD
properly.
Unless I missing something, smd_if
and txp:variable
to the rescue. The ugly code:
<txp:variable name="has_events" value='{events}' />
<txp:smd_if field="{day}" operator="le" value="9">
<txp:variable name="day" value="0{day}" />
<txp:else />
<txp:variable name="day" value="{day}" />
</txp:smd_if>
<txp:smd_if field="{month}" operator="le" value="9">
<txp:variable name="month" value="0{month}" />
<txp:else />
<txp:variable name="month" value="{month}" />
</txp:smd_if>
<txp:if_variable name="has_events" value="">
{day}
<txp:else />
<a href="/test/?month={year}-<txp:variable name="month" />-<txp:variable name="day" />">{day}</a>
</txp:if_variable>
So, the feature request you probably already guessed is to add the two-digits day and month as a replacement variable…
And while we are here, what does Mr. Dawson think about the following?
{day:d}
or {day:%d}
or {day|d}
or {day|%d}
, and so on…
Yeah, it looks even uglier! It remembers me about filters on Django templates.
I totally ignore if that magic is even possible, but hey, this is an smd_
plugin…
Finally, I wonder why TXP use ?month=
instead of ?date=
. It seems that the word “date” is more appropiate for the URL var than “month”.
Finally, finally: haven’t tried yet how to list all dates for a particular recurring/spanned event when in individual article context, but I’ve been mentally tinkering and I think the way is just using some tags in tags like this
<txp:if_individual_article>
<txp:smd_article_event id='<txp:article_id />' ... />
</txp:smd_article_event>
And we can go even further… what about displaying (on individual article context) not just the all the dates for a particular event, but also doing some fun/useful/clever stuff? Like highlighting the next one, or separating dates by past and current/future, or show only future.
I have no doubt it’s possible by cleverly using a combination of smd_if
, smd_cal_now
, smd_article_event
and a few others…
Expect more ugly code!
As Alex said, this plugin is fun, and it seems to give us mortals almost endless possibilities.
Offline
#302 2009-06-02 08:51:13
Re: smd_calendar: complete schedule / event / calendar / diary
maniqui wrote:
{day}
and{month}
return single digits for day or month<=
9.
Good point. I’ll have to find a way of allowing you to pad them with zeros. Hmmm. I don’t really want to add {day_padded}
or {day_with_leading_zero}
or anything like that so I’ll try to think of some creative way of allowing you to choose which version you want out of the replacements.
smd_if
andtxp:variable
to the rescue.
Very cool code, maniqui. I like this level of ingenuity when a plugin fails to do its job properly :-) The tag flexibility and people like you putting them to such innovative uses are what makes TXP so brilliant.
And while we are here, what does Mr. Dawson think about the following?
{day:d}
or{day:%d}
or{day|d}
or{day|%d}
Not sure I follow you. How would you use this syntax? My initial thought on handling padding was to do something like this: {day:PAD:2:0}
(i.e. PAD the day to 2 characters and put 0s in front) but it’s ugly as sin and not very intuitive, so I think I’ll rethink. Perhaps {day_with_leading_zero}
is actually an attractive proposition after all ;-)
I wonder why TXP use
?month=
instead of?date=
.
Beats me. Marshall — author of mdp_calendar — recognised the ‘day’ deficiency and allowed ?date=
which he then translated to a ?month=
internally to pass to TXP so it understood what’s going on. ?month=2009-06
makes little sense to me!
haven’t tried yet how to list all dates for a particular recurring/spanned event when in individual article context
Take a look at Example 4 in the docs. The 2nd part of that example details a way of using the calendar as a booking form to show all (in this case recurring) dates associated with the current article. With some extension homework that I’ve deliberately left to the reader(!) you could submit the form with the chosen date in it or even incorporate the date in a hyperlink so you can use it on another page.
what about displaying (on individual article context)… the next one, or separating dates by past and current/future, or show only future.
In an individual article context, remember that you can still call smd_article_event because it behaves like article_custom. So you can make a single call to it in a sidebar (without if_individual_article tags) and then use nefarious logic to detect when we reach certain points. A simple(ish) example to highlight current and next events:
<txp:variable name="this_artid" value='<txp:article_id/>' />
<txp:smd_article_event section="events">
<txp:if_variable name="curr" value="1">
<div class="the_next">
<txp:permlink>NEXT: <txp:title /></txp:permlink>
</div>
<txp:variable name="curr" value="" />
<txp:else />
<txp:smd_if field="thisid" operator="eq" value="txpvar:this_artid">
<txp:variable name="curr" value="1" />
<div class="current">
<txp:permlink>« <txp:title /></txp:permlink>
</div>
<txp:else />
<div class="an_event">
<txp:permlink><txp:title /></txp:permlink>
</div>
</txp:smd_if>
</txp:if_variable>
</txp:smd_article_event>
As you say, since the articles are in ascending date order by default, similar logic could be applied to check if we’ve reached the currently displayed article and flip a txp:variable to indicate that any events afterwards are future. By definition, all events that came before it were ‘past’.
Last edited by Bloke (2009-06-02 08:54:32)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
#303 2009-06-02 14:02:31
Re: smd_calendar: complete schedule / event / calendar / diary
Bloke, thanks for your reply.
maniqui wrote:
And while we are here, what does Mr. Dawson think about the following?
{day:d}
or{day:%d}
or{day|d}
or{day|%d}
Bloke wrote:
Not sure I follow you. How would you use this syntax?
As per my suggested idea, I was thinking about using strftime as “modificators” or “filters”. So, in the example above, {day:%d}
would return the day as a “two-digit day of the month (with leading zeros)”, and {day:%e}
would return the day as a “day of the month, with a space preceding single digits”, and so on. The %
could be dropped off for the sake of clarity and brevity. The :
could be a pipe (|
), to look more like a “filter”, although I think the :
is clearer.
Bloke wrote:
Take a look at Example 4 in the docs.
Thanks, I will.
maniqui wrote:
And we can go even further… what about displaying (on individual article context) not just the all the dates for a particular event, but also doing some fun/useful/clever stuff? Like highlighting the next one, or separating dates by past and current/future, or show only future.
I have no doubt it’s possible by cleverly using a combination of smd_if, smd_cal_now, smd_article_event and a few others…
Bloke wrote:
In an individual article context, remember that you can still call smd_article_event because it behaves like article_custom. (…)
Dear Bloke… I’m already at that TXP ninja level (I hope!) ;). Although I really appreciate the posted code, because it will certainly be helpful some day.
But I think you misunderstood my request (not really a request to you, but just thinking out loud), but I may also probably expressed wrong myself in my poor english.
As a follow up to the how to list all dates for a particular recurring/spanned event, I was tinkering about how to highlight/filter the next date on that list for this recurring event, and not the next event among a list of events/articles.
In other words, I wasn’t talking about a list of events, but a list of dates for an event, and how to achieve clever/fun/useful markup on that list (next event, divide by past, future, current dates for this event, etc)
That’s the exercise I’m going to practice now and hope to come back with the solution… :D
Last edited by maniqui (2009-06-02 14:03:14)
Offline
#304 2009-06-02 14:07:09
Re: smd_calendar: complete schedule / event / calendar / diary
maniqui
Thanks for the clarification on your proposal. I’ll think about it.
how to highlight/filter the next date on that list for this recurring event
Ah, ok. Then Example 4 is definitely your friend. Combining the sentiment from that example with the code in my not-very-useful example above will get you there. Look forward to see what you can come up with. If it spawns any more plugin attributes then all the better ;-)
Last edited by Bloke (2009-06-02 14:08:26)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
#305 2009-06-05 23:51:54
Re: smd_calendar: complete schedule / event / calendar / diary
A follow up.
Goals:
- on individual article: to display the event details and also list all the dates for a recurring event
- on article list (section context):
- if there is a
date=
URL var defined, then output a list of events for that particular date. - if there isn’t a
date=
URL var, then list “all” events (the ones determined by the tag attributes).
- if there is a
Alpha version (read comments for insight):
<txp:if_individual_article>
<!-- show the article -->
<txp:article>
<h2><txp:title /></h2>
<!-- feel free to include other txp article tags here, like body, custom fields, etc -->
<!-- on a next version, the following should be output conditionally, only if the event is a recurring event -->
<p>This event recurrs on the following dates:</p>
<txp:smd_article_event id='<txp:article_id />' stepfield="custom_1" eventlimit="9999" limit="9999" wraptag="ul" break="li">
<txp:posted />
</txp:smd_article_event>
</txp:article>
<txp:else />
<!-- we are on an article list -->
<txp:smd_if field="urlvar:date" operator="defined">
<!--
if there is a ?date=YYYY-MM-DD url var, then generate a list of articles for that day.
Check the way the var {smd_if_date} is used inside smd_cal_now for the "from" and "to" attributes.
I have had to used smd_cal_now because when I tried to use something like
from="{smd_if_date}" or
to="{smd_if_date}"
the plugin didn't generate any output.
It was as if "from" and "to" didn't understand a date like this: 2009-06-10 at all.
So I needed to use smd_cal_now to transform {smd_if_date} to something like "10 June 2009", and that worked fine for "from" and "to"...
Also, I need to set "to" attribute to one day offset in the future. If "from" and "to" are equal, then nothing is output.
-->
<txp:smd_article_event section="test" form="#terminArtikelListe" time="any" sort="Posted asc" stepfield="custom_1" skipfield="custom_2" omitfield="custom_3" extrafield="custom_4" from='<txp:smd_cal_now now="{smd_if_date}" format="%d %B %Y" />' to='<txp:smd_cal_now now="{smd_if_date}" offset="1 day" format="%d %B %Y" />' eventlimit="1" />
<txp:else />
<!-- if there is no URL var, then output a list of articles -->
<txp:smd_article_event section="test" form="#terminArtikelListe" time="any" sort="Posted asc" />
</txp:smd_if>
</txp:if_individual_article>
It’s very simple, really.
Of course, there is a lot of room for improvement.
Now, some issues and ideas that would be great to be able to develop further:
- on the individual article, I haven’t find a way inside a
txp:smd_article_event
to test which kind of event is this individual article. Is it arecur
? is itstandard
? is itmulti
? I don’t know! The flags that are available fortxp:smd_calendar
don’t seem to be available fortxp:smd_article_event
. - on the individual article, it gets even trickier if you would like to test it outside the
txp:smd_article_event
but still inside thetxp:article
. Of course, one could say: “Why don’t you just simple usetxp:if_custom_field
and test for values on custom fields likestepfield
,extrafield
, etc, and/or also usetxp:if_expires
/txp:expires
to see if this event is recurrent/spanned/standard, etc…?”. But then, I think it will be really hard with all the many nested conditionals for testing which kind of event is this one.
So, Bloke… here comes the request:
Could there by an easy way (a few new tags? ;) ) to know, inside a txp:article
, what kind of event is the one being rendered, without relying on <txp:smd_article_event />
?
In other words, some kind of is_standard
, is_recur
, is_spanned
boolean, already available for txp:article
(¿probably, relying on the same inner mechanisms that smd_calendar plugin already uses to determinate what type of event is this article?).
Thanks in advance.
Last edited by maniqui (2009-06-06 13:58:15)
Offline
#306 2009-06-06 00:31:43
- nardo
- Member
- From: tuvalahiti
- Registered: 2004-04-22
- Posts: 743
Re: smd_calendar: complete schedule / event / calendar / diary
thnx Maniqui, I wasn’t aware smd_if could do that … (that smd has more plugins than a datacentre)
Offline
#307 2009-06-06 11:47:00
- nardo
- Member
- From: tuvalahiti
- Registered: 2004-04-22
- Posts: 743
Re: smd_calendar: complete schedule / event / calendar / diary
I’ve returned to the small
calendar – because some days may have more than 1 event – and I figure I don’t really need individual articles, just listings…
so the small
calendar outputs URLs like this:
http://website.dev/?date=2009-06-25&s=events
On that events section page, I’ve got
<txp:smd_article_event section="events">
<h3><txp:title/></h3>
<p><txp:posted /></p>
<txp:body />
</txp:smd_article_event>
But output is everything from the previous month and the upcoming month… i.e. it doesn’t seem to be displaying just the event for 25 June.
?!
EDIT
OK got it working, I followed Maniqui’s example directly above, adding time from
and to
Last edited by nardo (2009-06-06 12:03:56)
Offline
#308 2009-06-06 12:18:56
- alexandra
- Member
- From: Cologne, Germany
- Registered: 2004-04-02
- Posts: 1,370
Re: smd_calendar: complete schedule / event / calendar / diary
Hi nardo, maniquis example above referrs to this testcase which is a “faked” big calendar. We had lot of trouble with the small cal and it seems better to shrink the big cal into a small version. another advantage on the long run is, if you ever have recurring events than you have to switch to a faked big cal anyway.
Currently i am cleaning up the testsite and i have to add some stuff like categories etc.. and test that but you are happily invited to get login to have a look at the code.
nardo schrieb:
OK got it working, I followed Maniqui’s example directly above, adding time
from
andto
do you referr here to the small or big cal?
Offline
#309 2009-06-06 12:23:01
- nardo
- Member
- From: tuvalahiti
- Registered: 2004-04-22
- Posts: 743
Re: smd_calendar: complete schedule / event / calendar / diary
small cal … I don’t need recurring events to show on the small cal … I would use the big calendar but I need the link on the day to go to a URL like http://website.dev/?date=2009-06-25&s=events
Offline
#310 2009-06-06 13:17:23
Re: smd_calendar: complete schedule / event / calendar / diary
maniqui
Nice example. Couple of points:
- The
from
andto
should work out of the box BUT are potentially brain-damaged depending on a few things: 1) your basic prefs date format, 2) Your gmt/dst setting relative to the time of year. For example,<txp:smd_cal_now />
returns5 Jun 2009
if I tell it to get a calendar entry from today! Coupled with the strtotime() weirdness this can leave some dates incorrectly calculated. If your basic prefs date format is something dateish likedd mm yyyy
then try modding the plugin on line 1377. Change the last line of smd_cal_now from:
return safe_strftime($format, $now, $gmt, $lang);
to:
return strftime($format, $now);
and see if you can get away without specifying the format
attribute in your tag.
- Testing the event type inside smd_article_event is probably doable. I can load the flags array the same as I do in the calendar and then you will be able to use smd_if_cal in your form/container.
- Making the above work inside txp:article is, however, pretty tough. But maybe I can write it cleverly such that you can simply wrap your txp:article tag with a simple tag that specifies which custom fields to ‘watch’ for. If I can do that then I can load the flags up and you’ll be able to use smd_if_cal inside your article form/container. No promises: this is just pie-in-the-sky thinking right now
nardo / alexandra
I get the message loud and clear; the minical sucks. It shall be cast from the plugin in due course and subject to a lifetime of sitting in a hot room with nothing but a toasting fork and the complete works of Barry Manilow playing on loop.
Last edited by Bloke (2009-06-06 13:19:27)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
#311 2009-06-08 07:53:40
- alexandra
- Member
- From: Cologne, Germany
- Registered: 2004-04-02
- Posts: 1,370
Re: smd_calendar: complete schedule / event / calendar / diary
Hi all,
another weirdness concerning listing recurring events crossed my way:
On the Events Archive page here
i list a recurring event. That works fine – but if you look up the expiration date, which is the 30. Jun 2009 it is set to the 12. July for the article which is skipped/omitted from 18th to 20th June. So for the extra event the expiration date is not the one set for this event article but newly counted (22 days) from the extrafield day on (20th jun + 22 days= 12th July).
<txp:if_expires>
Expires: <txp:expires />
</txp:if_expires>
is this intended?
Offline
#312 2009-06-08 08:24:22
Re: smd_calendar: complete schedule / event / calendar / diary
alexandra wrote:
is this intended?
Yes.
Consider a date for a trade show that runs for 3 days starting 8th June. Thus it ends on the 10th June. If your trade show was incredibly popular, you might want to reschedule it later in the year. Instead of creating a new article you could add an extra date to the existing show via extrafield
and give the date in that custom field as “15 Aug 2009”. The event is again 3 days so the expiry becomes 17th Aug. It does not make sense to have the expiry of the event remain at 10th June — before the 2nd event takes place!
In other words, when you duplicate an event the entire event is copied to the new date and the time shifted accordingly. If you can find a real-life situation where it is undesirable to move a rescheduled event’s expiry time, then please let me know and I’ll see if I can find a way round it.
Remember that the expiry date only makes sense to site visitors if you employ spanned events. If you are repeating an event, the expiry determines the end of the repetition not the ‘width’ (span) of each event so you should probably not be displaying it in your case. Spanning and repetition are normally mutually exclusive, but consult the ‘+’ notation in the documentation for an exception.
Last edited by Bloke (2009-06-08 08:25:10)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline