Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#331 2010-09-15 17:30:30

alanfluff
Member
From: Ottawa, Canada
Registered: 2008-09-15
Posts: 222
Website

Re: smd_if: Generic multiple if condition tests

Sob…

I’ve tried so hard to work out how to do this simple (I am sure) test, trawled many pages of threads and the docs Stef kindly provides, but to no avail.

If anyone can put me out of my misery I would be very grateful.

I have a custom field, called, exactly: Fluffy dog this custom field is number 39 (using glz_custom_fields).

The field is of type ‘Select’ and is either null (not set) or has the value Yes.

I have tried to write an smd_if statement to check for Yes and I can’t seem to work out how to represent the name of the field — I actually have more logic to build with this but until I can work out the syntax, I’m not going there ;)

This works <txp:custom_field name="Fluffy dog" /> insomuch as it outputs Yes, but in the following attempts/tests all evaluate to nothing (no error, just no Yes):

<txp:smd_if field="custom39" operator="eq" value="Yes">Yes</txp:smd_if>
<txp:smd_if field="custom_39" operator="eq" value="Yes">Yes</txp:smd_if>
<txp:smd_if field="custom 39" operator="eq" value="Yes">Yes</txp:smd_if>
<txp:smd_if field="fluffy_dog" operator="eq" value="Yes">Yes</txp:smd_if>
<txp:smd_if field="Fluffy Dog" operator="eq" value="Yes">Yes</txp:smd_if>

I’ve also tried using "eq:NOSPACE" in case this was relevant, but to no avail.

ANY help, much appreciated. Cheers, -Alan


At LAST I’ve cheerfully donated to the core devs at #TXP. I only wish I were able to give more. Thanks to the devs and ALL fellow TXPers. -A

Offline

#332 2010-09-15 17:59:12

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,316

Re: smd_if: Generic multiple if condition tests

Alan, I don’t think you need a plugin for your issue.

<txp:if_custom_field name="Fluffy dog" val="Yes">
    <p>Yes, doggy is Fluffy.</p>
<txp:else />
    <p>Nope, shaggy dog!</p>
</txp:if_custom_field>

In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#333 2010-09-15 18:07:24

alanfluff
Member
From: Ottawa, Canada
Registered: 2008-09-15
Posts: 222
Website

Re: smd_if: Generic multiple if condition tests

Thanks Uli, you’re right! For my test case ;)

I actually have more logic to build with this but until I can work out the syntax, I’m not going there ;)

So once I get how to use custom fields with smd_if, I will be building more complex logic to work out some stuff here — only I dare not even start since I cannot get this simple test-case use to work (due to my inability to understand documentation I am sure).


At LAST I’ve cheerfully donated to the core devs at #TXP. I only wish I were able to give more. Thanks to the devs and ALL fellow TXPers. -A

Offline

#334 2010-09-15 18:20:31

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,316

Re: smd_if: Generic multiple if condition tests

Have you tried renaming the cf to a space-less name? If you need the space for proper looks for your client, there’s bot_cf_titles (Hm, haven’t got a link lying around. If you need it, I’ll mail you a copy.)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#335 2010-09-15 18:23:58

alanfluff
Member
From: Ottawa, Canada
Registered: 2008-09-15
Posts: 222
Website

Re: smd_if: Generic multiple if condition tests

Hi Uli, I think I have, I’ll try it again tho — I have over 40 fields and I am hoping I dont’ have to rename then all — kinda hoping there’s a simple, plugin-free solution for using smd_if with custom fields where the titles include spaces and/or mixed case.

I’ll keep testing in case I missed a combination that suddenly works.

Cheers, -Alan


At LAST I’ve cheerfully donated to the core devs at #TXP. I only wish I were able to give more. Thanks to the devs and ALL fellow TXPers. -A

Offline

#336 2010-09-15 18:39:18

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: smd_if: Generic multiple if condition tests

Alan,

Quoted from Textbook: http://textpattern.net/wiki/index.php?title=custom_field

Custom names may include letters (uppercase or lowercase), numbers and under_scores, but no spaces or other special characters.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#337 2010-09-15 18:40:42

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,485
Website GitHub

Re: smd_if: Generic multiple if condition tests

alanfluff

In theory there’s no need to rename the fields (although as maniqui says, it’s preferred to not use spaces) — try the field name in all lower case, because TXP internally converts them this way:

<txp:smd_if field="fluffy dog" operator="eq" value="Yes">Yes</txp:smd_if>

Or using a hyphen:

<txp:smd_if field="fluffy-dog" operator="eq" value="Yes">Yes</txp:smd_if>

If that doesn’t work, try some debug="1" and let me know the output — it might shed some light on things.

EDIT: Custom fields is one area that need serious love in TXP… one day.

Last edited by Bloke (2010-09-15 18:43:05)


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

#338 2010-09-15 18:45:16

alanfluff
Member
From: Ottawa, Canada
Registered: 2008-09-15
Posts: 222
Website

Re: smd_if: Generic multiple if condition tests

Julián

Colour me sheepish — thank you for pointing out this obvious thing I should have known. I feel bad.

Stef

Thanks, I will try those and see – most kind, taking the time to help someone with a RTFM problem…

Cheers, -Alan


At LAST I’ve cheerfully donated to the core devs at #TXP. I only wish I were able to give more. Thanks to the devs and ALL fellow TXPers. -A

Offline

#339 2010-09-15 18:49:33

alanfluff
Member
From: Ottawa, Canada
Registered: 2008-09-15
Posts: 222
Website

Re: smd_if: Generic multiple if condition tests

Bingo!

<txp:smd_if field="fluffy dog" operator="eq" value="Yes">Yes</txp:smd_if>

did it. Looks like one of the combos I didn’t try — the dash didn’t work but keeping to all lowercase did.

Thanks again all, and lesson learnt re naming of custom fields. Cheers, -Alan


At LAST I’ve cheerfully donated to the core devs at #TXP. I only wish I were able to give more. Thanks to the devs and ALL fellow TXPers. -A

Offline

#340 2010-09-19 21:15:28

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

Re: smd_if: Generic multiple if condition tests

New check request

<txp:variable name="test_me">1,2,3,4</txp:variable>
<txp:smd_if field="txpvar:test_me" operator="ge:COUNT" value="3">
  Yes, there are more than 3 value. We have _{smd_if_test_me_count}_ values in list
<txp:else />
  There are 3 or less values in list.
</txp:smd_if>

And when we run it we would get:

Yes, there are more then 3 value. We have _4_ values in list

And we can use list_delim attr for changing coma “,” to something else.

I’d like to use plugin in such case to check if article_image (or cf) has more than 2 id’s. Of course, i can create little php and insert counter in some txp:variable, but using only smd_if is such a txp-way method! :)


Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?

Offline

#341 2010-09-28 23:28:08

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 521

Re: smd_if: Generic multiple if condition tests

Stupid me:
How can I use the article’s section as field?
field=“section” does work on the section itself.

I need to compare the current article’s section (in form default) against a list of user-related sections, operator = “in”, to filter out articles which belong to another section.

Offline

#342 2010-09-28 23:49:32

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,485
Website GitHub

Re: smd_if: Generic multiple if condition tests

saccade wrote:

How can I use the article’s section as field?

field="section" should work. Can you post the tag in context with what you’re trying to do please and I’ll see if I can figure out what’s going on. You could also try adding debug=“4” so you can see all the various global ‘THIS’ arrays. The items on the left of the => signs are all names you can use in the field attribute. Might give you some insight into the logic.

the_ghost

I’ll try and get something working along these lines. Won’t be this week though.


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

#343 2010-09-29 00:14:38

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 521

Re: smd_if: Generic multiple if condition tests

This goes into my default-form:

<txp:smd_if field="section" operator="in" list_delim="," value='<txp:sac_special_groups_privs />' >   ...   <txp:else />   ...  </txp:smd_if>

<txp:sac_special_groups_privs /> lists some allowed sections: e.g. “articles,about,whatever”

But obviously “section” doesn’t work, when viewing the default page (where articles from other sections gather). First I thought it should work, because it showed me an article, but then it didn’t – e.g. when listing more than one. I tried the same in a listform but without improvement.

Replacing my own tag with a hardcoded list doesn’t work too.
Always the “else”-part is rendered :(
(I did an output of all variables. articles_sections are definitely part of the value’s given)

Last edited by saccade (2010-09-29 00:31:03)

Offline

#344 2010-09-29 00:30:17

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,485
Website GitHub

Re: smd_if: Generic multiple if condition tests

saccade wrote:

But obviously “section” doesn’t work

Ah, right. It does work but you’re falling foul of one of the default attributes. param_delim defaults to a comma and since you’re using the comma for list_delim as well the plugin is seeing the commas in the value attribute and simply splitting them using param_delim (it takes precedence).

To work round it, specify param_delim as some other character like a pipe or something.

Last edited by Bloke (2010-09-29 00:30:45)


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

#345 2010-09-29 00:36:40

saccade
Plugin Author
From: Neubeuern, Germany
Registered: 2004-11-05
Posts: 521

Re: smd_if: Generic multiple if condition tests

Sorry, changing param_delim doesn’t solve my problem.
Obviously: in individual_article_mode the if-part is rendered.
But in article-list-mode only the else-part is working.

EDIT
I changed my values delimiter to / but it didn’t work either

Last edited by saccade (2010-09-29 00:43:32)

Offline

Board footer

Powered by FluxBB