Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-09-23 20:47:45

robin746
Member
From: Ireland
Registered: 2007-09-22
Posts: 113
Website

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

#4 2008-09-23 21:43:57

robin746
Member
From: Ireland
Registered: 2007-09-22
Posts: 113
Website

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

#5 2008-09-23 22:30:32

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

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>

My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#6 2008-09-23 22:36:15

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: Beyond if_different

Haven’t tested if MattD’s suggestion works, but if it does, then he is a very clever guy. :D


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#7 2008-09-24 02:09:56

renobird
Member
From: Gainesville, Florida
Registered: 2005-03-02
Posts: 786
Website

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

Board footer

Powered by FluxBB