Textpattern Forum

You are not logged in. Register | Login | Help

#321 2010-04-17 20:28:41

sereal
Member
From: Indonesia
Registered: 2010-02-18
Posts: 55

Re: smd_if: Generic multiple if condition tests

hi Stef

I try to modify this with no luck

<txp:if_individual_article>
<txp:article_custom  limit="1">
<txp:smd_if field="smallORbig" operator="contains" value="big">
	<txp:article class="sec1" form="article_full_big" limit="2" />
<txp:else />
	<txp:article class="sec1" form="article_full" limit="2" />
</txp:smd_if>
</txp:article_custom>
<txp:else />
<txp:article_custom  limit="1">
<txp:smd_if field="smallORbig" operator="contains" value="big">
	<txp:article class="sec1" form="article_short_big" limit="2" />
<txp:else />
	<txp:article class="sec1" form="article_short" limit="2" />
</txp:smd_if>
</txp:article_custom>
</txp:if_individual_article>

there are 2 different article forms to use but those line of tags only pick the big one and ignoring the small
because some articles I have has custom_field valued small while other is big

do you have any idea Sir ?

thank you

Last edited by sereal (2010-04-17 20:29:21)


$(mydocument).notyetready(function() {});
dowebsitesneedtolookexactlythesameineverybrowser ?

Offline

#322 2010-04-18 05:44:32

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

Re: smd_if: Generic multiple if condition tests

Hi sereal.
Calling a txp:article inside a txp:article_custom is technically wrong.

You could try something like this:

<txp:if_individual_article>

  <!-- 
    As you are already at the individual-article context, 
    the value of any article field, like the custom field 'smallORbig',
    is already available for being used, or tested, like you're doing
    with smd_if. Also, class attribute isn't needed, as you aren't using
    the wraptag attribute (class attribute value applies to wraptag).
   -->

  <txp:smd_if field="smallORbig" operator="contains" value="big">
    <txp:article form="article_full_big" />
  <txp:else />
    <txp:article form="article_full" />
  </txp:smd_if>

<txp:else />

  <!-- 
    But here, you are at an article-list context, so the value for any
    article field will be available inside each iteration, but not outside
    it. So the following is *wrong*.  
   -->

<txp:hide>
  <!-- wrong, so we txp:hide it -->
  <txp:smd_if field="smallORbig" operator="contains" value="big">
    <txp:article form="article_short_big" limit="2" />
  <txp:else />
    <txp:article form="article_short" limit="2" />
  </txp:smd_if>
</txp:hide>

  <!-- 
    Instead, it would have been more correct to do it this way:
   -->

  <txp:article class="sec1" limit="2">
    <txp:smd_if field="smallORbig" operator="contains" value="big">
      ... some html and txp tags here, like txp:title, txp:body, etc...
    <txp:else />
      ... some html and txp tags here, like txp:title, txp:body, etc...
    </txp:smd_if>
  </txp:article>   
</txp:if_individual_article>

A better, shorter way to have the same functionality could have been this:

<txp:if_individual_article>

   <!-- 
      Here, you avoid using an smd_if to test 'smallORbig' custom_field value 
      (btw, I would call this cf just 'size').
      Of course, you should have to (re)name your forms to 'article_full_big'
      and 'article_full_small'.
      Also, I've set a default value for the custom_field, in case it has 
      been left empty. So, for any article you forgot (or decided) to leave
      custom_field value empty, that article will be rendered using 'article_full_small'
      form.
   -->

   <txp:article form='article_full_<txp:custom_field name="smallORbig" default="small" />' />

<txp:else />

   <!-- 
     OK, now you are at article-list context. Let's do a similar trick. 
     txp:article will fetch the list of articles, and on each iteration
     each article will be rendered using a particular form, according
     to the custom_field value. Of course, you will need to rename
    form 'article_short' to 'article_short_small'.
   -->

  <txp:article limit="2">
    <txp:output_form form='article_short_<txp:custom_field name="smallORbig" default="small" />'  />
  </txp:article>

</txp:if_individual_article>

Shorter and easier, right? And, in this version, no need for the great, invaluable smd_if swiss knife.

Note that when you use txp:tags inside other txp:tags (as attribute values), you will need to use single quote (‘) instead of double quote.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#323 2010-04-18 10:49:56

sereal
Member
From: Indonesia
Registered: 2010-02-18
Posts: 55

Re: smd_if: Generic multiple if condition tests

Hi maniqui

it’s been a week trying to solve this :(

you’re right I think I have to be more carefull on renaming my custom forms

your 1st example is not what I am trying to achieve because the first calls

<txp:if_individual_article>
<!-- 
    As you are already at the individual-article context, 
    the value of any article field, like the custom field 'smallORbig',
    is already available for being used, or tested, like you're doing
    with smd_if. Also, class attribute isn't needed, as you aren't using
    the wraptag attribute (class attribute value applies to wraptag).
   -->
  <txp:smd_if field="smallORbig" operator="contains" value="big">
    <txp:article form="article_full_big" />
  <txp:else />
    <txp:article form="article_full" />
  </txp:smd_if>
<txp:else />

this renders a blank page on my test :(

but your 2nd example really works !!!!!!! exactly what I need

thank you thank you


$(mydocument).notyetready(function() {});
dowebsitesneedtolookexactlythesameineverybrowser ?

Offline

#324 2010-04-18 17:06:55

merz1
Member
From: Hamburg
Registered: 2006-05-04
Posts: 994
Website

Re: smd_if: Generic multiple if condition tests

@maniqui Compliments for analysis, comments and better solution. Great value!


Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML

Offline

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

mericson
Member
Registered: 2004-05-24
Posts: 121
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: 121
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: Farnham, Surrey, UK
Registered: 2009-06-11
Posts: 1,599
Website

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: 5,909
Website

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.

Txp Builders – finely-crafted code, design and Txp

Offline

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

philwareham
Core designer
From: Farnham, Surrey, UK
Registered: 2009-06-11
Posts: 1,599
Website

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

Board footer

Powered by FluxBB