Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Beyond if_different
Here I am again for my monthly dose of Q&A. This time I can’t get if_different to do what I’d like. I’m feeding a form a list of articles cleverly sorted by colour. Something like the following can be used to display only the group headings. This will give me the colour heading and then a sequence of articles within that colour.
<txp:if_different>
<h2><txp:custom_field name=“colour” /></h2>
</txp:if_different>
<p><txp:title /></p>
But that’s rather simplistic. In my case I need to output a certain block of HTML before this section, and another after. This typical usage scenario seems impossible to do with if_different. The following will not work since the second if_different block has no content to trigger from.
<txp:if_different>
<div class=“wrapper”>
<h2><txp:custom_field name=“colour” /></h2>
</txp:if_different>
<p><txp:title /></p>
<txp:if_different>
</div>
</txp:if_different>
Ideas?
(My actual scenario is a lot more complicated than this.)
robin
Offline
#2 2008-09-23 21:06:45
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Beyond if_different
This is a known limitation of if_different. You can work around it like this (if it’s acceptable to you to start the list with an empty div):
<txp:if_first_article>
<div style="display:none;">
</txp:if_first_article>
<txp:if_different>
</div>
<div class="wrapper">
<h2><txp:custom_field name="colour" /></h2>
</txp:if_different>
<p><txp:title /></p>
<txp:if_last_article>
</div>
</txp:if_last_article>
(My actual scenario is a lot more complicated than this.)
Then I don’t know if this will help you…
Offline
#3 2008-09-23 21:14:56
- rsilletti
- Moderator
- From: Spokane WA
- Registered: 2004-04-28
- Posts: 707
Re: Beyond if_different
If you are using SVN you could use variable and if_variable to toggle your closing div when you need to.
Offline
Re: Beyond if_different
Thanks! Els, that is a good work-around that mostly works for me at this time. The complexities I referred to make it less than ideal but a lot better than what I was working with before.
robin
Offline
Re: Beyond if_different
I’m really not very familiar with if_different but could you do something like this?
<txp:if_different>
<div class=“wrapper”>
<h2><txp:custom_field name=“colour” /></h2>
</txp:if_different>
<p><txp:title /></p>
<txp:if_different>
<!--<txp:custom_field name=“colour” />-->
</div>
</txp:if_different>
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
Re: Beyond if_different
Haven’t tested if MattD’s suggestion works, but if it does, then he is a very clever guy. :D
Offline
Re: Beyond if_different
Anyone tested what MattD posted yet?
Because it sure looks like it would work – that is some smart stuff right there folks. ;)
Last edited by renobird (2008-09-24 02:10:36)
Offline
Pages: 1