Textpattern Forum

You are not logged in. Register | Login | Help

#331 2010-06-11 01:34:45

maniqui
Moderator
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 2,989
Website

Re: smd_if: Generic multiple if condition tests

Do you know this “another article” that you want to check for a value in the custom field? or “another article” is just “any other article”?


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#332 2010-06-11 08:18:36

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 5,925
Website

Re: smd_if: Generic multiple if condition tests

th3lonius

I think I get what you’re doing but I’m not quite sure so I’ll hedge my bets here a bit. If it’s not quite right, the ideas in this example will probably get you moving in the right direction.

<txp:if_individual_article>
<txp:if_custom_field name="link_thingy">

  <txp:variable name="link_to_find"><txp:custom_field name="link_thingy" /></txp:variable>
  <txp:variable name="got_one" value="0" />

   <txp:article_custom>
      <txp:smd_if field="txpvar:got_one, body" operator="eq, contains" value="0, txpvar:link_to_find">
         <txp:hide> If we found a matching article, store its URL and bomb out </txp:hide>
         <txp:variable name="got_one" value='<txp:permlink />' />
      </txp:smd_if>
   </txp:article_custom>

   <txp:if_variable name="got_one" value="0">
      <txp:custom_field name="link_thingy" />
   <txp:else />
      <a href="<txp:variable name="got_one" />"><txp:custom_field name="link_thingy" /></a>
   </txp:if_variable>

</txp:if_custom_field>
</txp:if_individual_article>

It just grabs the custom field data you want to check from the current article and then uses an article_custom to iterate over every article until you find one that contains the custom field data in the body text. If it finds one, it stops looking (well, sort of!). Once it’s done with the article_custom it checks to see if it found a matching article and links to it. If not, it just displays the raw custom field value.

It’s untested and it’s not quick, but should work. I think. As your site grows you might be better off with smd_query.

Last edited by Bloke (2010-06-11 08:19:51)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern.

Txp Builders – finely-crafted code, design and Txp

Online

#333 2010-06-14 19:44:22

th3lonius
Member
From: Iowa City, IA
Registered: 2010-02-09
Posts: 67
Website

Re: smd_if: Generic multiple if condition tests

maniqui wrote:

Do you know this “another article” that you want to check for a value in the custom field? or “another article” is just “any other article”?

Any other article. Stef’s example code does basically what I want. It checks the value in the custom field of this current individual article against the same field in all other articles.

My only problem, Stef, is that your code always returns a link so it seems to be checking the current article and, naturally, always finding the value its looking for. I think it would work perfectly if there is a good way to exclude checking the current article in the article custom call.

EDIT: I also had the thought that <txp:article_custom /> allows restricting to articles with a specified custom field name so I tried this:

<txp:article_custom director="txpvar:link_to_find">

with director being the name of the custom_field I’m checking but that didn’t work.

Last edited by th3lonius (2010-06-14 19:46:54)

Offline

#334 2010-06-14 20:19:07

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 5,925
Website

Re: smd_if: Generic multiple if condition tests

th3lonius wrote:

a good way to exclude checking the current article in the article custom call.

Ah, didn’t think of that. Yeah, that could screw things up a bit.

Add this line to the declaration section along with the other txp:variables:

<txp:variable name="this_id" value='<txp:article_id />' />

and then use this smd_if line instead:

<txp:smd_if field="thisid, txpvar:got_one, body" operator="not, eq, contains" value="txpvar:this_id, 0, txpvar:link_to_find">

See if that works.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern.

Txp Builders – finely-crafted code, design and Txp

Online

#335 2010-06-15 12:51:11

th3lonius
Member
From: Iowa City, IA
Registered: 2010-02-09
Posts: 67
Website

Re: smd_if: Generic multiple if condition tests

It doesn’t work. The link remains on every article and every one receives the current article’s permlink from the operation.

Offline

#336 2010-06-22 15:14:17

wornout
Member
From: Italy
Registered: 2009-01-20
Posts: 254
Website

Re: smd_if: Generic multiple if condition tests

Hi Stef,
I use smd_if for render a part of an article (which is populated with custom fields) but it doesn’t work.
I don’t know where is the bug.
Can you help me?
This is my code:

<txp:smd_if field="variante-1, variante-2, variante-3" operator="isused" logic="or">
<div id="bottom-details">
<h4>Varianti</h4>
<div id="product-models">

<txp:if_custom_field name="variante-1">
<div class="model">
<div class="model-code">
<p>Articolo <txp:custom_field name="variante-1" /></p>
</div><!-- model-code -->
<div class="model-desc">
<txp:upm_textile>
<txp:custom_field name="descrizione-1" />
</txp:upm_textile>
</div><!-- model-desc -->
</div><!-- model -->
</txp:if_custom_field>

<txp:if_custom_field name="variante-2">
<div class="model">
<div class="model-code">
<p>Articolo <txp:custom_field name="variante-2" /></p>
</div><!-- model-code -->
<div class="model-desc">
<txp:upm_textile>
<txp:custom_field name="descrizione-2" />
</txp:upm_textile>
</div><!-- model-desc -->
</div><!-- model -->
</txp:if_custom_field>

<txp:if_custom_field name="variante-3">
<div class="model">
<div class="model-code">
<p>Articolo <txp:custom_field name="variante-3" /></p>
</div><!-- model-code -->
<div class="model-desc">
<txp:upm_textile>
<txp:custom_field name="descrizione-3" />
</txp:upm_textile>
</div><!-- model-desc -->
</div><!-- model -->
</txp:if_custom_field>

</div><!-- product-models -->
</div><!-- bottom-details -->
</txp:smd_if>

Offline

#337 2010-08-06 00:40:16

mrdale
Moderator
From: Walla Walla
Registered: 2004-11-19
Posts: 2,064
Website

Re: smd_if: Generic multiple if condition tests

Bloker: how do I use this to simply test for the existence of multiple values as opposed to a single value. I tried using this:

<txp:smd_if field="article_image" operator="contains" value="," >

to no avail…

any suggestions

Offline

#338 2010-08-06 00:45:20

maniqui
Moderator
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 2,989
Website

Re: smd_if: Generic multiple if condition tests

hi Dale,

try <txp:smd_if field="article_image" operator="contains" value="," param_delim=";">.
That should work.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#339 2010-08-06 01:35:52

mrdale
Moderator
From: Walla Walla
Registered: 2004-11-19
Posts: 2,064
Website

Re: smd_if: Generic multiple if condition tests

Ok that worked. Muchas Gracias Señor.

The problem was compounded a double escaping that I neglected…

Offline

#340 2010-08-15 14:51:35

NicolasGraph
Member
From: Strasbourg, France
Registered: 2008-07-24
Posts: 146
Website

Re: smd_if: Generic multiple if condition tests

Hi,

Is it possible to compare the parent attribute to several values without repeating the attribute ?

Thanks for your answers


Nicolas

Offline

Board footer

Powered by FluxBB