Extend if_different using the variable and if_variable tags

The txp:if_different> tag can be used to display the contained statement only when its value differs from the preceding value. An example is – when you publish more than one article per day – to display the posting time not for every article but once per day:

<txp:if_different>
   <!-- heading - only once per day -->
   <h3><txp:posted format="%Y %e %B" /></h3>
</txp:if_different>
<h4><txp:permlink><txp:title /></txp:permlink></h4>
<txp:body />

The tag has the limitation that it can only contain one other txp tag, so if you would like to display other parts of the article beside the date, if_different won’t work.

You can solve that by using the variable and if_variable tags.

<txp:variable name="date" value='<txp:if_different><txp:posted format="%Y %e %B" /></txp:if_different>' />

<txp:if_variable name="date" value="">
   <!-- the date does not differ from the previous one, don't display anything -->
<txp:else />

   <!-- display the date once -->
   <h3><txp:posted format="%Y %e %B" /></h3>

   <!-- display the day's most recent article in full -->
   <h3><txp:permlink><txp:title /></txp:permlink></h3>
   <txp:body />

</txp:if_variable>

<!-- display the permlinked article titles for the other articles published on this date -->
<txp:if_variable name="date" value="">
<p><txp:permlink><txp:title /></txp:permlink></p>
</txp:if_variable>
comments powered by Disqus