Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2004-11-23 20:19:34

Remillard
Plugin Author
From: Lenexa, KS
Registered: 2004-05-16
Posts: 169

[ARCHIVED] mdn_if_custom: custom field conditionals

This plugin’s functionality can now be achieved using txp tags

This plugin provides a number of conditionals for evaluating custom fields. It provides empty, notempty, equal, notequals, and additionally provides an <else /> clause to provide a result for the inverse of the conditional as well.

Usage:
<code> <txp:mdn_if_custom field="n" [empty="1"] [notempty="1"] [equal="text1, text2, text3, ..."] [notequal="text1, text2, text3, ...] [case="1"] > This text will be parsed and output if the conditional evaluates as true. [ <else /> This text will be parsed and output if the conditional evaluates as false. ] </txp:mdn_if_custom> </code>

NOTE: Items in square brackets indicate optional capability. The brackets should not be used in the tag creation.

Parameters:
  • field – This parameter is REQUIRED. This is a number from 1 to 10 specifying the field the conditional should operate on.
  • empty – This parameter is OPTIONAL. If this is set to a 1, then the field will be checked to see if it is empty.
  • notempty – This parameter is OPTIONAL. If this is set to a 1, then the field will be checked to see if it is not empty. Yes, this is the same as empty with an else clause, however it didn’t seem useful to make someone type the else clause out if there was no use for a truth clause.
  • equal – This parameter is OPTIONAL. The text in quotes will be checked to see if it matches the field contents. The text may include multiple values. The comparison is done case-insensitive by default.
  • notequal – This parameter is OPTIONAL. The text in quotes will be checked to see if it doesn’t match the field contents. The text may include multiple values. The comparison is done case insensitive by default.
  • case – This parameter is OPTIONAL. If set to 1, this paramter will make the conditional comparisons for equal and notequal be case sensitive.
  • <else /> – This clause is OPTIONAL. If included, the text following the <else /> will be output if the conditional evaluates as false.
Notes:
  • Be careful if you attempt to nest this IF/THEN/ELSE conditional inside itself. The checking for <else /> is pretty intolerant at the moment, and you will likely get the truth text and the false text mixed up. If you are going to nest them, make SURE that the nested IF does NOT have an ELSE clause.
  • <else /> must be spelled exactly as shown. <else/> will not work. It has to be <else />. This will be true until I figure out a regular expression to match variants of else with whitespace insensitivity.
  • There is some error checking done, so if you do something like leave out a parameter, it ought to let you know by spitting out some text.

Download the plugin
Version: 1.1

I hope this helps someone.

Regards,
Remillard

Last edited by Remillard (2004-11-23 20:20:48)

Offline

#2 2004-11-24 18:08:17

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: [ARCHIVED] mdn_if_custom: custom field conditionals

Am I right in assuming that this plugin should be used in an article form?
Is it then possible to put other txp tags or code inside the tags instead of text? For instance, if a custom field contains “something” a certain class is applied to that article, if not, not?

If this is not the way to use the plugin, can you give an example?

Last edited by doggiez (2004-11-24 18:09:14)

Offline

#3 2004-11-24 19:56:27

Remillard
Plugin Author
From: Lenexa, KS
Registered: 2004-05-16
Posts: 169

Re: [ARCHIVED] mdn_if_custom: custom field conditionals

Yes, this should be used in an article form. I probably ought to make that explicitly clear above. If it’s not in an article form, there is no article ID number to provide the context for looking up the custom fields.

It should be possible to put almost anything in the truthclause and falseclause regions. I return the parsed output of these sections, so TXP tags, and plugin tags ought to render appropriately.

Just as an example of usage, lets say our normal text is black on white background, but if custom field 1 says “reverse” then we want to switch that.

<code> <txp:mdn_if_custom field="1" equal="reverse"> <div class="reversetext"> This ought to be white on black. </div> <else /> <div class="normaltext"> This ought to be black on white. </div> </txp_mdn_if_custom> </code>

Something like that ought to work.

Did this answer the question?

Last edited by Remillard (2004-11-24 19:56:54)

Offline

#4 2004-11-24 21:15:37

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: [ARCHIVED] mdn_if_custom: custom field conditionals

Yes, thank you very much! I think I can find a good use for this…

Offline

#5 2004-11-24 23:29:24

alicson
Member
Registered: 2004-05-26
Posts: 465
Website

Re: [ARCHIVED] mdn_if_custom: custom field conditionals

one of the most useful plugins ever ;)
really.


textpattern.org :: find and share Textpattern resources
docs.textpattern.io :: Textpattern user documentation

Offline

#6 2004-11-24 23:59:50

blumie607
Member
Registered: 2004-03-08
Posts: 175
Website

Re: [ARCHIVED] mdn_if_custom: custom field conditionals

Wow. This is a great plugin.


bludrop studios .::. Creative Expression

Offline

#7 2004-12-08 15:57:39

apo
Member
From: Germany
Registered: 2004-10-27
Posts: 53

Re: [ARCHIVED] mdn_if_custom: custom field conditionals

ah… maybe this could solve my problem

would
< txp:mdn_if_custom field=“1” equal=“1” >
< p ><txp:title />[…]< /p >
< /txp_mdn_if_custom >

work (in the list form)? what do you think?

edit: how do i input code?

Last edited by apo (2004-12-08 15:58:19)

Offline

#8 2004-12-08 17:40:50

Remillard
Plugin Author
From: Lenexa, KS
Registered: 2004-05-16
Posts: 169

Re: [ARCHIVED] mdn_if_custom: custom field conditionals

I think this would work. The thread hasn’t gotten a lot of responses, and I’m not sure if that’s because it “just works” or if now one’s using it much.

Anyhow, basically here, if the custom field #1 had the contenst “1”, then the block ought to output. You might also just be able to check for empty/notempty and that might be easier for your article management.

Offline

#9 2004-12-09 09:42:47

apo
Member
From: Germany
Registered: 2004-10-27
Posts: 53

Re: [ARCHIVED] mdn_if_custom: custom field conditionals

yeah, might be right… but it works each way, so its a question of what you prefer.

btw: i get the following error whenever the plugin outputs something… whats wrong here?

Warning: strpos(): Empty delimiter. in /textpattern/publish.php(767) : eval()’d code on line 313

Warning: strpos(): Empty delimiter. in /textpattern/publish.php(767) : eval()’d code on line 313

Warning: strpos(): Empty delimiter. in /textpattern/publish.php(767) : eval()’d code on line 313

this (767) is a line of the function doPlugins or something like that…

well, i’ll try to reinstall the plugin (maybe i missed an encoded character or something?) and using the empty/noempty-thing

btw, think thats a real great plugin. custom fields are usable for that many needings… hehe, simply great :-)

edit: using notempty fixed it

Last edited by apo (2004-12-09 10:17:48)

Offline

#10 2005-04-20 13:11:17

kemie
Plugin Author
From: mexico<-->sweden
Registered: 2004-05-20
Posts: 495
Website

Re: [ARCHIVED] mdn_if_custom: custom field conditionals

I’m having a hard time getting this to work on RC1. here’s what i have:

<txp:mdn_if_custom field=“6” notempty=“1” >Some content
</txp:mdn_if_custom>

I also tried
<txp:mdn_if_custom field=“6” empty=“1”>EMPTY
<else />
Some content
</txp:mdn_if_custom>

and none seem to work. Is it a RC3 thing, or am I doing something wrong?


~~~~~~~~~~~~~| monolinea.com | pixilate.com | istockphoto.com/kemie |~~~~~~~~~~~~~

Offline

#11 2005-04-20 13:14:10

kemie
Plugin Author
From: mexico<-->sweden
Registered: 2004-05-20
Posts: 495
Website

Re: [ARCHIVED] mdn_if_custom: custom field conditionals

Sorry, forgot my code tags:
I’m having a hard time getting this to work on RC1. here’s what i have:
<code>
<txp:mdn_if_custom field=“6” notempty=“1” >Some content
</txp:mdn_if_custom>
</code>

I also tried
<code>
<txp:mdn_if_custom field=“6” empty=“1”>EMPTY
<else />
Some content
</txp:mdn_if_custom>
</code>

and none seem to work. Is it a RC3 thing, or am I doing something wrong?


~~~~~~~~~~~~~| monolinea.com | pixilate.com | istockphoto.com/kemie |~~~~~~~~~~~~~

Offline

#12 2005-04-20 15:42:51

Remillard
Plugin Author
From: Lenexa, KS
Registered: 2004-05-16
Posts: 169

Re: [ARCHIVED] mdn_if_custom: custom field conditionals

Hi,

I’ll check into it. I know it works in RC1 because Textpattern Resources uses it. I haven’t check it out recently so I’ll try to get it running on a sandbox sometime today.

Offline

Board footer

Powered by FluxBB