Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: smd_countdown: time to an event
Hi Stef (or anyone else feeling clever).
I’m coming up against a bit of a hurdle with this. I would like to display the number of days before the article expiry occurs. This is my code, currently:
<txp:smd_countdown><txp:smd_time_info display="day_total" label="day, days" labelafter="1" show_zeros="0" labelspacer=" " class="" break="" wraptag="" /></txp:smd_countdown>
which outputs the number of days (with a leading 0 if it’s a single digit number of days), then a space, then ‘day’ or ‘days’, then a line break. I’m a little confused because I thought show_zeros
dictates whether leading zeros are displayed, and with neither the wraptag
or break
set to anything, I figured it would display inline and not have any kind of break after the details are displayed.
Am I doing something wrong? Well, OK, I’m clearly doing something wrong, I’d very much like to know where I’ve made the error :)
Thanks in advance.
Last edited by gaekwad (2011-07-17 14:27:32)
Offline
Re: smd_countdown: time to an event
gaekwad wrote:
I thought
show_zeros
dictates whether leading zeros are displayed
Not quite. It’s confusingly titled (suggestions welcome for v2!) but show_zeros="0"
prevents any zero-count items from being displayed at all. Best explained with example: if you chose to display the number of weeks and days to go until your expiry, then:
- with 30 days to go: “04 weeks 02 days”
- with 10 days to go: “01 week 03 days”
- with 5 days to go : “05 days”
- with 5 days to go and
show_zeros="1"
: “00 weeks 05 days”
To silence leading zeros for individual numbers, check out the pad
attribute. I think pad="1"
will do the trick in your case.
Incidentally, shouldn’t your tag be:
<txp:smd_countdown to="expires">
<p>TIME'S UP!</p>
<txp:else />
<txp:smd_time_info blah blah />
</txp:smd_countdown>
?
and with neither the
wraptag
orbreak
set to anything, I figured it would display inline and not have any kind of break after the details are displayed.
This one’s not your fault: it’s TXP’s fault and we have to work around it in this version of the plugin. I forgot to document it, which is bad form.
Firstly, break
is the break between display items. In your case you’re only displaying one item so there’s nothing to break (if you were using display="week,day"
then your break tag would occur between the week and the day).
The rogue <br />
you’re seeing is actually produced by the label. This “feature” goes back a long way and is what prompted me to raise the doLabel enhancement issue that has yet to be resolved.
[ For background info, Txp has an internal function called doLabel()
which this plugin uses. If you don’t specify a labeltag
when calling that function, it automatically assumes “br”. But sometimes you truly do not want a break at all after your label — you want it inline. And the function cannot do this. It ought to be possible to specify something like labeltag=" "
as a cheat, but that just produces < >
after your label ]
Currently there’s no true fix. The only way round it I’ve found is to specify labeltag="span"
which at least wraps spans — an inline element — around your ‘days’ label. It’s not pretty but it’s better than a line break.
I could get round this by simply not using doLabel()
and writing that bit myself in the plugin but I felt doLabel()
was actually wrong in the core and should be fixed. Sadly I forgot about it and never fixed it. One day…
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
Re: smd_countdown: time to an event
Stef – you are a complete dude, and I thank you most kindly for your time and attention.
Next time I’m in Coventry I will buy you (proper) beer :)
Offline
Re: smd_countdown: time to an event
Bloke wrote:
Incidentally, shouldn’t your tag be:
<snip>
For completeness, yes, you’re right – but I’m doing something marginally clever and using smd_countdown
in an article form, so when the article expires it just disappears…so it seemed that code was surplus as no-one was ever going to see it. I’m all about fast page loads and reducing workload for TXP and the browser, so it got chopped.
Last edited by gaekwad (2011-07-18 12:55:10)
Offline
Re: smd_countdown: time to an event
gaekwad wrote:
I’m doing something marginally clever and using
smd_countdown
in an article form, so when the article expires it just disappears
Cunning, and logical. Only do what’s needed for the job. I like that.
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
Re: smd_countdown: time to an event
Hi,
I want to use the plugin and display the number of days left in a specific font, also using label before and after the countdown so need to isolate the number of days with a css id or class
“only 177 days to go”
tried to set class=“countdown” but no luyck so far, any suggestions?
Offline
Re: smd_countdown: time to an event
Ohh..my mistake sorry, it wasn’t a countdown case.
(but I am going to use it for something else in the same project)
Thanks anyway
Last edited by THE BLUE DRAGON (2012-07-25 11:54:52)
Offline
Re: smd_countdown: time to an event
I think I may have found a bug with v0.1
I’m using this markup:
(<txp:smd_countdown to="expires"><txp:else /><txp:smd_time_info display="day_total" labelafter="1" labelspacer=" " label="day to go, days to go" pad="" show_zeros="0" /></txp:smd_countdown>)
I expect to see something like this:
(3 days to go)
Instead, I see this:
(3 days to go
)
According to the browser inspector, there’s a <br>
inserted after the ‘to go’. First off, and with all due respect to Stef, it shouldn’t be there. Second, if it’s used anywhere, it should really be a <br />
and not a <br>
.
I’m a little wary of bleating about this since I may have my syntax wrong, and to be frank I can work around it, but I wanted to flag it.
Offline
Re: smd_countdown: time to an event
Hi Stef (and everyone else smarter than I).
I’m hoping you could advise where I’m going wrong with this scenario, or give me a pointer. I’d like to display the number of days until article expiry. Here’s the smd_countdown
code I’m using:
<txp:smd_countdown to="expires"><txp:smd_time_info display="day_total" /></txp:smd_countdown>
Here’s my code inline (excuse the squashed-ness):
<h4><small>Exp: <txp:if_expires><txp:expires format="%b %e, '%y" /> (<txp:smd_countdown to="expires"><txp:smd_time_info display="day_total" /></txp:smd_countdown>)<txp:else />none</txp:if_expires></small></h4>
…and here’s the output:
Exp: Jun 30, '14 ()
…and here’s the tag trace snippet:
<txp:if_expires>
[<txp:if_expires>: true]
<txp:expires format="%b %e, '%y" />
<txp:smd_countdown to="expires">
[<txp:smd_countdown to="expires">: false]
</txp:smd_countdown>
</txp:if_expires>
Article does expire, has a valid date recognised by if_expires
, but smd_countdown
doesn’t like it. What did I get wrong?
Thank you in advance.
Offline
Re: smd_countdown: time to an event
gaekwad wrote #278388:
Article does expire, has a valid date recognised by
if_expires
, butsmd_countdown
doesn’t like it. What did I get wrong?
This is a case where perhaps my logic doesn’t line up with real people’s expectations. I did agonise for ages over it at the time, but decided that the ‘true’ branch of the conditional smd_countdown tag should actually be the scenario executed when the time is reached. The ‘else’ block is what gets executed all the time the event has yet to be reached. Example from the docs:
<txp:smd_countdown to="expires">
Too late, you missed it :-(
<txp:else />
There's still time to get to the show...
</txp:smd_countdown>
My reasoning was that if you were only interested in showing when some event was reached (and not interested in the meantime), you wouldn’t want to have to put an empty <txp:else />
for no reason. So although it seems slightly counter-intuitive, you either need to put an empty else in your smd_countdown tag or set your prefs to publish expired articles and put a message in, like this:
<h4>Exp: <txp:if_expires>
<txp:expires format="%b %e, '%y" />
(<txp:smd_countdown to="expires">
Too late!
<txp:else />
<txp:smd_time_info display="day_total" />
</txp:smd_countdown>)
<txp:else />
none
</txp:if_expires></h4>
Does my backwards-ass logic make some kind of sense now?
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
Re: smd_countdown: time to an event
Bloke wrote #278409:
[…] the ‘true’ branch of the conditional smd_countdown tag should actually be the scenario executed when the time is reached. The ‘else’ block is what gets executed all the time the event has yet to be reached. […]
Does my backwards-ass logic make some kind of sense now?
Absolutely – and I should’ve read more clearly. Thank you, Stef – very helpful.
Offline
Re: smd_countdown: time to an event
Hi again, Stef (and anyone else smarter than I).
Some time ago, I made reference to a bug that I suspected was inserting <br>
into the code. Now I’ve come back to use this plugin again, I’ve pinpointed what appears to be triggering it.
This is the testing code containing the smd_countdown
block:
<h4 style="padding-top:0rem;">
<small>Exp: <txp:if_expires>
<txp:expires format="%b %e, '%y" /> (
<txp:smd_countdown to="expires">
<txp:else />
<txp:smd_time_info display="week" label="week, weeks" />
</txp:smd_countdown>
)
<txp:else />
none
</txp:if_expires>
</small>
</h4>
I was also using the labelafter
attribute but I’ve stripped that out until I can figure our what I’m doing wrong. With that code above, this generates a spurious <br>
after the label:
<h4 style="padding-top:0rem;"><small>Exp: Jun 30, '14 (weeks<br>21)</small></h4>
If I remove the label
attribute:
<txp:smd_time_info display="week" />
…the <br>
disappears:
<h4 style="padding-top:0rem;"><small>Exp: Jun 30, '14 (21)</small></h4>
What’s confusing me is that there’s no reference to <br>
in the plugin code, nor is there mention in the documentation to say that it’s set as a break tag. I’d be grateful for some advice on this, if anyone can help, please. Thanks!
Offline