Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#421 2015-02-27 17:53:44
Re: smd_if: Generic multiple if condition tests
If I hard code in “Active” – SMD_IF works fine.
Here is the debug code (in this example the variable is “gyx_status”):
TEST 1
array (
0 => 'txpvar',
1 => 'gyx_status',
)
array (
0 => 'contains',
)
array (
0 =>
array (
0 => 'Active',
),
)
@$replacements['{smd_if_gyx_status}'] = $variable["gyx_status"];
@$replacements['{smd_if_len_gyx_status}'] = strlen($variable["gyx_status"]);
$out[0] = (isset($variable["gyx_status"]) && strpos(strtolower($variable["gyx_status"]), strtolower('Active')) !== false) ? 'true' : 'false';
RESULT:
array (
0 => 'false',
)
REPLACEMENTS:
array (
'{smd_if_val1}' => 'Active',
'{smd_if_len_val1}' => 6,
'{smd_if_gyx_status}' => '<?php
return file_get_contents(\'http://wave.marineweather.net/test/test.php\');
?>',
'{smd_if_len_gyx_status}' => 86,
)
It does seem like it almost has to be hidden character(s). I’m trying to check with other tools…
Offline
#422 2015-02-27 19:07:15
Re: smd_if: Generic multiple if condition tests
I’ve reduced the output of the url to a single word – Active.
Something is still preventing SMD_IF from seeing it.
I may have to switch from coffee to Scotch.
Offline
#423 2015-02-27 22:27:48
Re: smd_if: Generic multiple if condition tests
towndock wrote #288644:
Something is still preventing SMD_IF from seeing it.
It’s not executing the code. I think maybe we should be using ‘echo’ instead of ‘return’, but it’s possible your prefs aren’t set to permit PHP to run? You’ve got mail.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
#424 2015-04-03 19:39:51
- phuture303
- Member
- Registered: 2008-09-14
- Posts: 127
Re: smd_if: Generic multiple if condition tests
Hi, I want to do a simple test: My custom field named oddFr1 has the value 15:00x, I’m using the glz_custom_field plugin.
<txp:smd_if field="oddFr1" operator="contains" value="x">
yes
<txp:else />
no
</txp:smd_if>
… but the result is “no” – and I don’t know why!
<txp:smd_if field="oddFr1" operator="contains" value="x">
[<txp:smd_if field="oddFr1" operator="contains" value="x">: false]
</txp:smd_if>
I tried 1500x instead of 15:00x and I tried with operator ends instead of contains. There must be something wrong but I don’t find it :-)
Thanks in advance!
David
Textpattern-Version: 4.5.7 (r5900), PHP-Version: 5.6.0 (56STABLE-STANDARD)
EDIT: Okay, found the problem – the naming of the custom field! oddFr1 doesn’t work, oddfr1 does. CamelCase is not accepted, too bad.
Last edited by phuture303 (2015-04-03 20:23:30)
Offline
#425 2015-04-03 21:39:19
Re: smd_if: Generic multiple if condition tests
phuture303 wrote #289716:
EDIT: Okay, found the problem – the naming of the custom field!
oddFr1doesn’t work,oddfr1does. CamelCase is not accepted, too bad.
Textpattern turns the field names (ASCII characters anyhow) to lowercase during extraction. Most likely smd_if doesn’t and because of it won’t find the field by the name.
Offline
#426 2015-04-04 05:32:20
- phuture303
- Member
- Registered: 2008-09-14
- Posts: 127
Re: smd_if: Generic multiple if condition tests
Gocom wrote #289720:
Textpattern turns the field names (ASCII characters anyhow) to lowercase during extraction. Most likely smd_if doesn’t and because of it won’t find the field by the name.
Thanks! Took me a while to fine out :-)
Offline
#427 2015-07-06 14:41:16
- mmelon
- Member
- Registered: 2006-03-02
- Posts: 95
Re: smd_if: Generic multiple if condition tests
Hi,
I am struggling today to do something that should be easy for smd_if. I am inside a <txp:category_list> container, and I want to output different markup based on the level of the current category.
<txp:php>
global $variable;
$variable['mainCategory'] = gps('maincat');
</txp:php>
<txp:category_list parent='<txp:variable name="mainCategory"/>' children="1" type="article">
some sort of smd_if condition to trap and branch on the category level.
Thanks for any insight,
Mike
Offline
#428 2015-07-06 19:45:31
- mmelon
- Member
- Registered: 2006-03-02
- Posts: 95
Re: smd_if: Generic multiple if condition tests
Hi, I’ve found my conditions won’t work as nothing is output in $parentcats unless I am in a ?c= category context. I just want to iterate over the parent category and children, and know what level they reside at as I am outputting them. Not sure why that needs a URL category context, when the category tag accepts a name attribute.
Offline
#429 2015-07-06 22:15:21
Re: smd_if: Generic multiple if condition tests
mmelon wrote #292679:
Not sure why that needs a URL category context, when the category tag accepts a name attribute.
Have you tried using category instead of c? That will check against the current category inside loops. At least, it should.
But even so, I’m not sure it’ll help you as I’m not entirely convinced this is achievable without some hacking. The operator does have the :LVLn and :KIDS modifiers, which might be able to help but it may mean stashing the results in a txp:variable and testing for it. Not pretty.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
#430 2016-01-30 10:46:04
Re: smd_if: Generic multiple if condition tests
If can’t seem to get this working. I want to test if comment_email == ‘a@b.com’, and if it is then execute a line of code.
<txp:smd_if field="<txp:comment_email />" operator="eq" value="a@b.com" case_sensitive="0">
<h1>execute some code</h1>
</txp:smd_if>
Never mind never mind. The solution was to use ‘ instead of “ around txp comment email.
Last edited by sochicomputerRU (2016-01-30 11:10:57)
Offline
#431 2016-03-14 17:24:04
- lionel865
- New Member
- Registered: 2016-03-14
- Posts: 1
Re: smd_if: Generic multiple if condition tests
Hello,
I have a problem and i don(t know what is it .
My code is :
<txp:smd_if field=“txpvar:section” operator=“not” logic=“or” value=“brunes,blondes, ambres,noires,speciales” >
//show anything
</txp:smd_if>
thanck
Offline
#432 2016-03-14 21:21:13
Re: smd_if: Generic multiple if condition tests
Not sure what you’re trying to do, but could you perhaps do it this way instead by using the else case of if_section:
<txp:if_section name="brunes,blondes,ambres,noires,speciales"><txp:else />
<p>This section is not brunes, blondes, ambres, noires or speciales</p>
</txp:if_section>
TXP Builders – finely-crafted code, design and txp
Offline
#433 2016-03-14 22:50:29
Re: smd_if: Generic multiple if condition tests
lionel865
If what jakob suggests isn’t what you’re intending, you might have more luck with this syntax for smd_if:
<txp:smd_if
field="txpvar:section"
operator="notin"
value="brunes/blondes/ambres/noires/speciales">
//show anything
</txp:smd_if>
Each time you were using the comma it was comparing the individual items in your list against the field but using the not operator for the first comparison only. Thereafter it used the default operator, eq. So your statement was equivalent to this:
<txp:smd_if
field="txpvar:section"
operator="not,eq,eq,eq,eq"
value="brunes, blondes, ambres, noires, speciales"
logic="or">
//show anything
</txp:smd_if>
Which failed because one of them matched exactly. What you probably meant was:
<txp:smd_if
field="txpvar:section"
operator="not, not, not, not, not"
value="brunes, blondes, ambres, noires, speciales"
logic="or">
//show anything
</txp:smd_if>
But the notin version is probably more efficient. And jakob’s is even better if it does what you want.
Hope that helps.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
#434 2016-04-14 06:04:12
- lazlo
- Member
- Registered: 2004-02-24
- Posts: 110
Re: smd_if: Generic multiple if condition tests
Hey Stef
Thanks for the wonderful plugin.
I have a problem constructing the correct call, and I am looking for guidance.
Currently my code looks like this:
<txp:variable name="direction" />
<txp:smd_if field="txpvar:direction" operator="in" value="Drama/Poetry/Fiction/Non-Fiction" logic="or">
<txp:output_form form="contributors_list" />
</txp:smd>
<txp:variable name=“direction” /> is populated through PHP from my site menu structure ?Drama ?Poetry ?Fiction ?Non-Fiction etc.
Parsing Drama, Poetry and Fiction work and they call <txp:output_form form=“contributors_list” /> but Non-Fiction does not. At first I thought it was the hyphen (dash) that was the problem so I removed it and that didn’t fix the problem.
But if I change the Non-Fiction to Non-Fict it will now call <txp:output_form form=“contributors_list” /> so it seems Non-Fiction doesn’t work because it contains “Fiction”.
I tried <txp:smd_if field=“txpvar:direction” operator=“eq, eq, eq, eq,” value=“Drama,Poetry,Fiction,Non-Fiction” logic=“or”> but it fails as well.
Preferably I would like to use “Non-Fiction” in the variable because it has downstream code that matches my category names.
Thanks in advance.
Last edited by lazlo (2016-04-14 06:04:47)
Offline
#435 2016-04-14 09:02:02
Re: smd_if: Generic multiple if condition tests
lazlo wrote #298607:
it seems Non-Fiction doesn’t work because it contains “Fiction”.
Very strange indeed. I tried it on my test box using a sanitised, hard-coded value of direction and it worked fine. Here’s my code. Note that I tidied up the closing smd_if tag too (but that probably doesn’t have a bearing on it) and dropped the logic attribute since the in operator implies it.
<txp:variable name="direction" value="Non-Fiction" />
<txp:smd_if field="txpvar:direction" operator="in" value="Drama/Poetry/Fiction/Non-Fiction">
Match made in heaven.
<txp:else />
No match this time :-(
</txp:smd_if>
So I wonder if there’s something else at play here. Firstly, could you go back to basics, copy the code above and see what you get out. If it works we may need to investigate how your direction variable is being populated. Perhaps it has a rogue space on the end of it or something, and it needs trimming first (though that wouldn’t explain why Non-Fict worked).
A few things you can try:
- Add
debug="2"to thesmd_iftag and check the values it is comparing match what you expect. - Swap the order of the items in the
valueattribute list soNon_Fictioncomes beforeFiction. - Check you’re using the very latest plugin version (0.91) or try the beta 0.92 (which I doubt will affect anything in this instance because it only adds pref matching support).
Past that I’m not sure what could be going on. If none of the above fixes it, by all means drop me a temporary login to the site (if possible) and I’ll see if I can figure it out in situ.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline