Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#253 2009-08-20 11:29:06

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

Re: smd_if: Generic multiple if condition tests

gomedia wrote:

Panic over

No worries. Sorry my plugin made you feel insane, albeit temporarily. This is where my stupid plugin attribute ‘fallback’ mechanism causes problems. If you specify an operator that doesn’t exist it drops back to using eq instead. Thus 6 != 3 :-)

I am guilty of violating software engineering rule #372 in most of my plugins:

“if a mistake is detected, inform the user about it and gracefully exit. Never make decisions on their behalf.”

*sigh* My University lecturer would shake his head in disappointment if he ever saw my code. I really should fix that in my plugins. One day…

Last edited by Bloke (2009-08-20 11:30:29)


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

#254 2009-08-27 09:44:31

txpnisti
Member
Registered: 2009-02-25
Posts: 23

Re: smd_if: Generic multiple if condition tests

Is it possible with smd_if to achieve “if not articles in this category, then yell it loud “ action?

I’m fighting with MLP and category list – I want to exclude empty categories. Using cbs_category list doesn’t work here as it doesn’t seem to use translated titles. So for workaround, if I use just native txp:category_list, and output all created categories, this could save me – or at least give some peace of mind.

Edit. Nevermind! I finally found a solution

tags for other searchers: list, only, article, categories, having, content.

Cool!

Last edited by txpnisti (2009-08-27 09:54:29)

Offline

#255 2009-09-24 18:07:38

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

Re: smd_if: Generic multiple if condition tests

Is it possible to use smd_if’s :LEN feature to figure out if the combined character length of three fields is greater than or equal to a particular value? I don’t know how to add the fields together before running it through the operator.

<txp:smd_if field="parent:LVL1:LEN,parent:LVL2:LEN,category:LEN" operator="ge" value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" debug="1">id="condense" </txp:smd_if>

(I am using 45 x’s for the value because the value=“45”, results in a length of only “2”)

Just curious if I am missing something… or if this a case where I need to use raw php somewhere?

Offline

#256 2009-09-24 19:30:08

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: smd_if: Generic multiple if condition tests

If it can’t be done in smd_if (I don’t know), there’s always adi_calc.


Code is topiary

Offline

#257 2009-09-25 20:36:54

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

Re: smd_if: Generic multiple if condition tests

photonomad wrote:

Is it possible to use smd_if’s :LEN feature to figure out if the combined character length of three fields is greater than or equal to a particular value?

No. Especially since the ‘parent’ feature is an smd_if goodie so it’s not available to other plugins like adi_calc. Even in PHP it’s a bit involved because you need to determine the parent and first child of the current category before you can begin to get their lengths and add them together.

What exactly are you trying to achieve? It looks as if you are conditionally adding an id attribute to a tag. Is there another way to test for what you want and insert the id that way?

P.S. The :LEN goes on the operator not the field.

Last edited by Bloke (2009-09-25 20:37:40)


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

#258 2009-09-26 02:32:37

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

Re: smd_if: Generic multiple if condition tests

I have a “breadcrumb” section/category menu working on my site with the help of smd_if and smd_parent. Style-wise, some of the category titles are pretty long, so my plan is to add an id to the containing div that will make the font smaller when the breadcrumb menu is too long to fit on one line. This is the code I have working for my menu using smd_if and smd_parent:

<div class="section_title">
<txp:smd_if field="parent:LVL1" operator="eq" value='<txp:smd_parent />'><txp:section name='<txp:smd_parent />' title="1" link="1" /></txp:smd_if><txp:smd_if field="parent:LVL2" operator="contains" value='<txp:smd_parent level="-1" />'>: <txp:category name='<txp:smd_parent level="-1" />' title="1" link="1" /></txp:smd_if>: <txp:category title="1" />
</div>

When you add up the combined character length for the top level parent and the second level parent (if it exists) and the current category, the maximum character length that I can get away with is around 44 characters (including spaces, etc). I am attempting to use something like this in the opening tag for the div:

<div <txp:smd_if field="parent:LVL1:LEN,parent:LVL2:LEN,category:LEN" operator="ge" value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" debug="1">id="condense" </txp:smd_if>class="section_title">

(again, I am using 45 x’s for the value because the value=“45”, results in a length value of only “2”)

This is what I get with debug.

Two issues:
1) I’d really like for the Title of the parent:LVL1, parent:LVL2, and category instead of the name (because some of the level 1 names have been shortened to match section names).
2) I can see in the debug that the plugin is only comparing the 45 character length to the first field value (parent:LVL1:LEN).

I would like to figure out the length of each field, then add them together, then compare that length to 45 characters.

Note: often times there is no character length for parent:LVL2 because it doesn’t exist (as in this debug example).

Sorry for the long post — hopefully this makes sense!

Last edited by photonomad (2009-09-26 02:34:36)

Offline

#259 2009-09-26 12:43:31

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

Re: smd_if: Generic multiple if condition tests

photonomad

Yup, makes sense. Could you use rvm_substr to shorten any long titles to a known number of characters/words?

I’d really like for the Title of the parent:LVL1, parent:LVL2, and category instead of the name

Good idea; I’ll see if that’s possible to get hold of in a meaningful way. Bearing in mind that titles may contain spaces I’ll need a better delimiter of course.

I can see in the debug that the plugin is only comparing the 45 character length to the first field value (parent:LVL1:LEN).

It’s not even doing that! You need to use the :LEN correctly and you must have an operator for each field, e.g.:

<txp:smd_if field="parent:LVL1, parent:LVL2, category" operator="ge:LEN, ge:LEN, ge:LEN" value="15, 15, 15" logic="or">

That’s not ideal because it only checks if any of the items exceed 15 characters, but if you tweak the values a little bit you might find a close approximation that sets the id on a reasonable spread of categories. The fact you’re using category names instead of titles notwithstanding!

Last edited by Bloke (2009-09-26 12:45:25)


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

#260 2009-09-26 19:26:28

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

Re: smd_if: Generic multiple if condition tests

Bloke

Thanks for the feedback!

Could you use rvm_substr to shorten any long titles to a known number of characters/words?

I don’t want to limit the length of the titles. I’d much rather compute the length and change the style only when the total length of the category titles is particularly long.

I’ll see if that’s possible to get hold of in a meaningful way. Bearing in mind that titles may contain spaces I’ll need a better delimiter of course.

thanks for looking into that Bloke!

You need to use the :LEN correctly and you must have an operator for each field

thanks for correcting me on that — though, it still looks like it isn’t working. When compared (ge:LEN) to a value of 15, names with a length of 8 characters result in “true” and names with a length of 18 also result in “true” (also, I had to go back to putting 15 x’s for the value, otherwise, the value just shows up as “2” in the debug)

IF you are curious and want to see examples (site still in development):

this is a page with all three category levels

this is a page with only a level1 category and a subcategory

Last edited by photonomad (2009-09-26 19:27:29)

Offline

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

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

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

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

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: 290
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

Board footer

Powered by FluxBB