Textpattern CMS support forum

You are not logged in. Register | Login | Help

#251 2009-08-20 10:53:53

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

Re: smd_if: Generic multiple if condition tests

gomedia wrote:

I think I’m going mad.

And justifiably so if the plugin can’t count :-D

However, I tried it on my dev account in both an article form and directly in the article (in case it was Textile getting in the way) and both times received:

6 is divisible by 3

So something must be going squiffy somewhere along the line in your install. fwiw I’m using v0.8 of smd_if; are you? And what does adding debug="2" (or 3) give you? Anything meaty that we can chew on to try and track this down?


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

#252 2009-08-20 11:10:05

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,225
Website

Re: smd_if: Generic multiple if condition tests

Panic over … Thought I was on 0.77, was actually on 0.74 but upgraded to 0.8 & it works perfectly. Just a minor insanity after all. Sorry for troubling you.

Adi

Offline

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

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

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: 287
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,781
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: 8,620
Website

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: 287
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: 8,620
Website

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

Board footer

Powered by FluxBB