Textpattern CMS support forum

You are not logged in. Register | Login | Help

#21 2014-01-23 10:19:10

gaekwad
Admin
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 2,633

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

#22 2014-01-23 20:05:36

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,813
Website

Re: smd_countdown: time to an event

gaekwad wrote #278388:

Article does expire, has a valid date recognised by if_expires, but smd_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

#23 2014-01-23 20:17:56

gaekwad
Admin
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 2,633

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

#24 2014-01-30 17:40:03

gaekwad
Admin
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 2,633

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

#25 2014-01-31 09:04:43

etc
Developer
Registered: 2010-11-11
Posts: 3,401
Website

Re: smd_countdown: time to an event

Hi Pete (not that I’m smarter…)

if you see doLabel() in the code, that’s your guy.

Offline

#26 2014-01-31 10:23:29

gaekwad
Admin
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 2,633

Re: smd_countdown: time to an event

Hi Oleg – thank you for the info. I’ve also had a brief back-and-forth with Stef over email and you’re right: it’s doLabel(). I will figure out a workaround.

Offline

#27 2014-01-31 15:50:47

etc
Developer
Registered: 2010-11-11
Posts: 3,401
Website

Re: smd_countdown: time to an event

If you pass it through rah_replace, mind that it’s actually <br />, that your browser’s inspector displays as <br>.

Offline

#28 2014-02-01 01:21:36

gaekwad
Admin
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 2,633

Re: smd_countdown: time to an event

It’s like you’re in my head, Oleg. I tried rah_replace with <br> and it didn’t work, so left it until I had time to investigate further. Once again you’ve saved me a bunch of time and work -thank you very much!

Offline

#29 2014-02-03 11:44:45

gaekwad
Admin
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 2,633

Re: smd_countdown: time to an event

For completeness, here’s the code I used to get around the doLabel() snag:

<h4 style="padding-top:0rem;">
	<small>Exp: <txp:if_expires>
		<txp:expires format="%b %e, '%y" /> (
			<txp:rah_replace from="<br />" to="">
				<txp:smd_countdown to="expires">
				<txp:else />
					<txp:smd_time_info display="week" label="week, weeks" />
				</txp:smd_countdown>
			</txp:rah_replace>
		)
		<txp:else />
			none
		</txp:if_expires>
	</small>
</h4>

Mucho thanks to Stef and Oleg.

Offline

#30 2014-10-29 08:50:57

alivato
Member
Registered: 2011-03-31
Posts: 147

Re: smd_countdown: time to an event

How to delete <br>

<txp:smd_countdown to="31 Dec 2014 23:59:59">
<txp:else />
 <txp:smd_time_info display="day"
           labelafter="1" labelspacer=" "
           label="d." show_zeros="0" />
 <txp:smd_time_info display="hour"
           labelafter="1" labelspacer=" "
           label="h." show_zeros="0" />
 <txp:smd_time_info display="minute"
           labelafter="1" labelspacer=" "
           label="m." show_zeros="0" />
</txp:smd_countdown>

Last edited by alivato (2014-10-29 08:54:01)

Offline

Board footer

Powered by FluxBB