Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#385 2012-03-01 07:20:40
Re: smd_if: Generic multiple if condition tests
Can I do something like this?
<txp:smd_if field="urlvar:foo, urlvar:foo2" logic="and" operator="undefined"> // View all articles here <txp:else /> <txp:smd_if value="urlvar:foo" operator="isused"> // View subset of articles based on value of foo here </txp:smd_if> <txp:smd_if value="urlvar:foo2" operator="isused"> // View subset of articles based on value of foo2 here </txp:smd_if> </txp:smd_if>
Offline
#386 2012-03-01 14:28:11
Re: smd_if: Generic multiple if condition tests
wornout wrote:
Can I do something like this? <snip>
With v0.91, yes. Note that you may have to put the operator in twice in the first line:
<txp:smd_if field="urlvar:foo, urlvar:foo2" operator="undefined, undefined">
...
I’m not sure if it short circuits the operators or not, I can’t remember. Either way you don’t need logic="and"
because that’s default behaviour.
An alternative construct, in theory to do the same thing:
<txp:smd_if field="urlvar:foo, urlvar:foo2" logic="or" operator="defined, defined">
<txp:smd_if value="urlvar:foo" operator="isused">
// View subset of articles based on value of foo here
</txp:smd_if>
<txp:smd_if value="urlvar:foo2" operator="isused">
// View subset of articles based on value of foo2 here
</txp:smd_if>
<txp:else />
// View all articles here
</txp:smd_if>
Last edited by Bloke (2012-03-01 14:28:24)
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
#387 2012-03-01 21:18:54
Re: smd_if: Generic multiple if condition tests
Thanks Stef!
Offline
#388 2012-06-05 13:14:45
Re: smd_if: Generic multiple if condition tests
Hi,
I’m having troubled using this tag with a multi-select field defined using glz_custom_fields.
The field name is called Utilizzo and the options are:
Professionale
Educazione
Tempo-libero
In an article I have opted for the first two.
If I use <txp:smd_if field="Utilizzo" operator="contains" value="Professionale" >This is a test</txp:smd_if>
I don’t get anything displayed.
If I change the field type to Select, than it works.
If I just display the value of the field using <txp:custom_field name="Utilizzo"/>
I get: Educazione|Professionale
Any ideas?
Offline
#389 2012-06-07 12:05:53
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,310
Re: smd_if: Generic multiple if condition tests
I’d say it might be an upper/lowercase issue. If you hadn’t written this:
If I change the field type to Select, than it works.
On the other hand: the field type is saved in the txp_prefs table. Where (I’d bet any amount) smd_if never goes looking for its evaluations.
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
#390 2012-06-07 12:34:24
Re: smd_if: Generic multiple if condition tests
If you hadn’t written this: If I change the field type to Select, than it works. …
Presumably it’s because you can’t choose multiple options with a normal select
so there will be only one item and no |
in the custom field value. In effect the operator contains
is then eq
.
I can’t immediately see why it’s not working either, unless the pipe (|) is being (mis)interpreted as an operator. Not sure if upper/lowercase should be an issue as smd_if is by default case-insensitive, although you can set that with the case_sensitive
operator.
You might also want to try stripping out the |
from the field by using smd_if’s filter attribute. I’ve not tried it but maybe:
<txp:smd_if field="Utilizzo" operator="contains" value="Professionale" filter="/[^a-zA-Z]+/" replace=" ">
This is a test
</txp:smd_if>
If I’ve not made a mistake that should replace anything that is not A-Z or a-z in the field with a space…
Last edited by jakob (2012-06-07 12:37:39)
TXP Builders – finely-crafted code, design and txp
Online
#391 2012-06-07 13:16:09
Re: smd_if: Generic multiple if condition tests
Hi,
I changed the field name and options to all lower case and it works (without jakob’s filter).
Not sure why.. but I’m happy :)
Thanks for your help!
Offline
#392 2012-07-26 15:29:43
Re: smd_if: Generic multiple if condition tests
For the record (and maybe for the help documents too).
id
is always the id of current page’s article (i.e. the id of current individual article)thisid
is the id of current context article. For example, in anarticle_custom
loop,thisid
takes the value of the article currently being iterated.
For example, if you need to simulate txp:if_article_id
, using smd_if, it would be like this:
<txp:smd_if field="thisid" operator="eq" value="?id">
The advantage of this one over txp:if_article_id
is that you could check for other conditions, using logic="OR"
.
Offline
#393 2012-09-28 20:22:49
Re: smd_if: Generic multiple if condition tests
I’m not sure if I understand how the parent
value for field
attribute works. I’m not even sure if I needed for what I’m trying to achieve:
Is it possible to test if current (global) category has no children? I don’t think I need to traverse up the category tree for that, but I may be missing something.
Offline
#394 2012-12-12 14:49:58
- gfdesign
- Member
- From: Argentina
- Registered: 2009-04-20
- Posts: 401
Re: smd_if: Generic multiple if condition tests
Hi, a quick question.
How I should use it if I want to know if a body or excerpt article has content or not ?
I was using <txp:chh_if_data> but it does not work / comply when the output is less than 39 characters :| (unless when I’m displaying articles from a specific category)
<txp:chh_if_data>
<txp:article_custom form="body" pgonly="0" limit="1" section='<txp:section />' sort="Posted asc" status="5" category='<txp:category title="0" />' />
<txp:else/>
<p>NO THERE CONTENT IN BODY ARTICLE</p>
</txp:chh_if_data>
Thanks
Last edited by gfdesign (2012-12-12 14:56:31)
Offline
#395 2012-12-12 19:48:53
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,310
Re: smd_if: Generic multiple if condition tests
Without plugin?
<txp:variable name="checkcheck"><txp:article_custom form="body" limit="1" section='<txp:section />' sort="Posted asc" status="sticky" category='<txp:category title="0" />' /></txp:variable>
<txp:if_variable name="checkcheck" value="">
<p>NO THERE CONTENT IN BODY ARTICLE</p>
<txp:else/>
<txp:variable name="checkcheck" />
</txp:if_variable>
status 5 is sticky, right? (No further proofreading done.)
Last edited by uli (2012-12-12 21:19:33)
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
#396 2012-12-12 20:03:05
- GugUser
- Member
- From: Quito (Ecuador)
- Registered: 2007-12-16
- Posts: 1,473
Re: smd_if: Generic multiple if condition tests
Or:
<txp:if_custom_field name="body">
something
<txp:else />
other thing
</txp:if_custom_field>
Offline