Textpattern CMS support forum

You are not logged in. Register | Login | Help

#261 2009-09-26 19:35:24

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,621
Website

Re: smd_if: Generic multiple if condition tests

photonomad wrote:

When compared (ge:LEN) to a value of 15, names with a length of 8 characters result in “true”

Hmmm, you’re right. Something’s banjaxed there isn’t it. I’ll check if the plugin is broken.


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

#262 2009-09-26 20:05:44

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,621
Website

Re: smd_if: Generic multiple if condition tests

Well the plugin works OK for me but I did have to do some thinkin’!

This might help diagnose the problem better. Add these lines after line 159 of the plugin (in v0.8 it’s after the $parentCats = $rfld = implode(" ", $items); line):

if ($debug && $parentCats) {
   echo "++ PARENT CATS ++";
   dmp($parentCats);
}

When you refresh your page look for the PARENT CATS output and check that what you see there is actually the category you expect and are comparing against.

For the record, don’t pay too much attention to the debug output where it states that the replacement value of {smd_if_len_val1} is 2. It’s correct, the length of the string you put in to the value field is 2, but that information is not used in the test you are performing here. Thus you should not use 15 x’s, you should use the value 15 because xxxxxxxxxxxxxxx is always “greater than” the number 15 (think in ascii terms: ‘x’ is greater than the ‘1’ and ‘5’ characters so you’ll always see a true result).

I have a hunch that the problem is you might be testing the wrong LVL here. Hopefully the additional debug will help guide you to choosing the correct one. As I say, I did a simple test and it returned true when the length of my LVL2 cat’s name was >= 15 chars and false otherwise.

I should probably have that debug in there all the time because it’s very handy. Let me know how you get on and if it leads you to the correct test I’ll put that debug info in the next version.


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

#263 2009-09-26 21:42:27

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,621
Website

Re: smd_if: Generic multiple if condition tests

Try v0.81 which adds two new modifiers to the parent arsenal:

  • TTL allows you to compare the category title against something
  • KIDS allows you to take action based on the number of child categories a given LVL has

I didn’t bother changing the delimiter in the end.

The debug output has also been improved as detailed in my earlier post so you can see exactly what you’re comparing against beneath the PARENT INFO segment.


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

#264 2009-09-27 02:49:31

photonomad
Member
Registered: 2005-09-10
Posts: 287
Website

Re: smd_if: Generic multiple if condition tests

Bloke Wow, that was quick! Thanks so much for helping me through that! I added TTL to the fields and replaced the x’s with a numeric value. Seems like testing for a title length greater than 23 (and adding logic=“or” to the tag) does the trick for now! :)

by the way… I was testing the correct levels… I just threw everything off with the x’s (and I needed to add logic=“or”).

Last edited by photonomad (2009-09-27 02:58:15)

Offline

#265 2009-11-19 20:09:44

photonomad
Member
Registered: 2005-09-10
Posts: 287
Website

Re: smd_if: Generic multiple if condition tests

I use txp:output_form to reference the main menu from every page template in my site. I was just working on the error_default page and realized that the menu code below wasn’t displaying section links like it does everywhere else in the site:

<txp:section name="nameofsection" link="1" title="1" wraptag="h2" <txp:smd_if field="section,parent" operator="eq,contains" value="nameofsection,nameofsection" logic="or">class="selected"</txp:smd_if> />
<txp:section name="anothernameofsection" link="1" title="1" wraptag="h2" <txp:smd_if field="section,parent" operator="eq,contains" value="anothernameofsection,anothernameofsection" logic="or">class="selected"</txp:smd_if> />

I ended up having to place the menu code directly in the error_default page and remove the smd_if part from each txp:section tag to get it to work. I just thought it was kind of strange that smd_if would break the txp:section tag only on error_pages and thought I’d mention it here.

Offline

#266 2009-11-25 04:07:29

speeke
Member
From: Bruny Island, Australia
Registered: 2009-03-29
Posts: 161
Website

Re: smd_if: Generic multiple if condition tests

I have the following:

<txp:smd_if field="urlvar:countries" operator="in" value="a-b/c-e/f-j/k-m/n-r/s/t-z">
    <txp:article listform="article_list" country_range="{smd_if_countries}" limit="1" sort="title" />
</txp:smd_if>

which works like a charm. But I was wondering if there was a way to replace a-b/c-e/f-j/k-m/n-r/s/t-z with a query that tests for all the values of the custom field name country_range and then places those results in the value attribute of the <txp:smd_if> tag.

Such that the first line of code above becomes:

<txp:smd_if field="urlvar:countries" operator="in" value="[results of query here, separated by a slash]">

“People who value their privileges above their principles soon lose both.”
Dwight D. Eisenhower

Offline

#267 2009-11-25 07:26:36

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,251
Website

Re: smd_if: Generic multiple if condition tests

speeke wrote:

<txp:smd_if field=“urlvar:countries” operator=“in” value=”[results of query here, separated by a slash]”>

Could you use smd_query and tags within tags?


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#268 2009-11-25 20:49:52

speeke
Member
From: Bruny Island, Australia
Registered: 2009-03-29
Posts: 161
Website

Re: smd_if: Generic multiple if condition tests

MattD wrote:

Could you use smd_query and tags within tags?

I was thinking along those lines, but I can’t see how to create a query that runs through all the values of the column custom_13, and then outputs them in a string: a-b/c-e/f-j/k-m/n-r/s/t-z where / is the separator (custom_13 contains values in the format: a-b).

I’ve started with this:

<txp:smd_query query="SELECT DISTINCT custom_13 FROM textpattern WHERE section = 'section_name' AND status = 4 GROUP BY custom_13">

but after that I’m in the dark. I’m looking to create a variable that holds the complete string.


“People who value their privileges above their principles soon lose both.”
Dwight D. Eisenhower

Offline

#269 2009-11-25 21:10:57

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,251
Website

Re: smd_if: Generic multiple if condition tests

not tested but this should work if I’m reading the plugin instructions correctly. I did test the smd_query part with a slightly different query.

<txp:variable name="fieldValues" value='<txp:smd_query query="SELECT DISTINCT custom_13 FROM textpattern WHERE section = 'section_name' AND status = 4 GROUP BY custom_13">{custom_13}/</txp:smd_query>'/>

Last edited by MattD (2009-11-25 21:11:34)


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#270 2009-11-25 21:49:46

speeke
Member
From: Bruny Island, Australia
Registered: 2009-03-29
Posts: 161
Website

Re: smd_if: Generic multiple if condition tests

I’ve tried this query, but am not getting any output. No errors either :/


“People who value their privileges above their principles soon lose both.”
Dwight D. Eisenhower

Offline

Board footer

Powered by FluxBB