Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#325 2010-05-23 22:17:04

mericson
Member
Registered: 2004-05-24
Posts: 137
Website

Re: smd_if: Generic multiple if condition tests

The opening article suggests this plugin can be used for conditional based on IP Address. I don’t know what variable(s) to use to achieve that, can someone post the use of smd_if for IP address conditional ?

Thanks,

Mark

Offline

#326 2010-05-23 23:16:45

mericson
Member
Registered: 2004-05-24
Posts: 137
Website

Re: smd_if: Generic multiple if condition tests

Figured out how to test for an IP address…

 <txp:smd_if field="svrvar:REMOTE_ADDR" operator="eq" value="127.0.0.1">
     ...conditional content here...
 </txp:smd_if>

mericson wrote:

The opening article suggests this plugin can be used for conditional based on IP Address. I don’t know what variable(s) to use to achieve that, can someone post the use of smd_if for IP address conditional ?

Offline

#327 2010-06-07 13:31:45

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,545
Website GitHub Twitter

Re: smd_if: Generic multiple if condition tests

Hi, I want to increment a number in some javascript (it’s a custom navigation system for a jQuery Cycle gallery) wrapped inside an article tag depending on how many articles are listed (up to a maximum of 15), I think I could use smd_if for this task but don’t know how to implement it. The resulting code would be for example:

$('#article3').click(function(){$('.cycle').cycle(0);return false;});
$('#article7').click(function(){$('.cycle').cycle(1);return false;});
$('#article9').click(function(){$('.cycle').cycle(2);return false;});
$('#article13').click(function(){$('.cycle').cycle(3);return false;});
etc..

It’s the .cycle(0) part of the javascript that I would need to increase, through .cycle(1) up to .cycle(14) if there are 15 articles. Here is my code so far…

<txp:article limit="15">
     $('#article<txp:article_id />').click(function(){$('.cycle').cycle(0);return false;});
</txp:article>

Is there a way of doing that? Something like .cycle(<txp:smd_if … blah blah

Last edited by philwareham (2010-06-07 13:33:15)

Offline

#328 2010-06-07 13:35:03

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 10,568
Website GitHub

Re: smd_if: Generic multiple if condition tests

philwareham wrote:

I want to increment a number in some javascript

You’re probably better off with rvm_counter, adi_calc or aks_var for this job.


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

#329 2010-06-07 13:56:16

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,545
Website GitHub Twitter

Re: smd_if: Generic multiple if condition tests

Thanks perfect – used adi_calc as suggested, thanks Steph.

Here is final working code:

<txp:variable name="cycleinc" value="0" />
<txp:article limit="15">
     $('#article<txp:article_id />').click(function(){$('.cycle').cycle(<txp:adi_calc name="cycleinc" display="1" />);return false;});
<txp:adi_calc name="cycleinc" add="1" />
</txp:article>

Offline

#330 2010-06-11 00:01:41

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

Re: smd_if: Generic multiple if condition tests

I need to be able to execute an anchor tag (turn some text in to a link) if, and only if, the custom field data from the article in which it appears is also in another article. Only one custom field to check here; the value must appear in more than one article so that links to lists of articles with this value are created automatically.

Seems like txp:smd_if is up to the challenge, but I’m new to it and I can’t think of how to use it properly to accomplish this. Any ideas?

EDIT: Repost from “How do I?” forum. Couldn’t get any help there.

Offline

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

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
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: 10,568
Website GitHub

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. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#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: 10,568
Website GitHub

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. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#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: 256
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

Board footer

Powered by FluxBB