Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#16 2004-07-27 18:49:29

jimb
Archived Plugin Author
From: Chicago, IL, USA
Registered: 2004-07-22
Posts: 27
Website

Re: swf_if_empty

I was needing support for custom fields on a project today, so I hacked together the excellent rei_show_custom and the equally excellent swf_not_empty to add support for custom fields in conditional statements. Here is the result for anyone interested:

<code>
function custom_not_empty($atts, $contents) { global $thisarticle; $id = $thisarticle[“thisid”];

if (is_array($atts)) extract($atts); $wraptag = (empty($wraptag)) ? “” : $wraptag; $customid = (empty($customid)) ? 1 : $customid; $custom_field = “custom_”.$customid; $res = safe_rows($custom_field, “textpattern”,“id=’$id’”); $out = $res0[$custom_field]; if (isset($minlength)) { if ($minwords < count(explode(” “, $out))) { return parse($enclosed); }; } elseif(!empty($out)) { return parse($contents); }; </code>

I have not tested this extensively, but it should work.

Offline

#17 2004-07-29 05:57:35

nardo
Member
From: tuvalahiti
Registered: 2004-04-22
Posts: 743

Re: swf_if_empty

any kind soul interested in compiling this? will swap for (musical) food

Offline

#18 2004-07-29 16:03:12

lee
Member
From: Normandy, France
Registered: 2004-06-17
Posts: 831

Re: swf_if_empty

Not sure, but try this out: (copy and save as jim_custom_not_empty.txt)

<code>
<?php

$plugin=‘YTo4OntzOjQ6Im5hbWUiO3M6MjA6ImppbV9jdXN0b21fbm90X2VtcHR5IjtzOjY6ImF1dGhvciI7czo1OiJKaW0gQiI7czoxMDoiYXV0aG9yX3VyaSI7czoyNzoiaHR0cDovL2luZmluaXRlZXhwYW5zZS5uZXQvIjtzOjc6InZlcnNpb24iO3M6MzoiMS4wIjtzOjExOiJkZXNjcmlwdGlvbiI7czoxNDY6IkkgaGFja2VkIHRvZ2V0aGVyIHRoZSBleGNlbGxlbnQgcmVpX3Nob3dfY3VzdG9tIGFuZCB0aGUgZXF1YWxseSBleGNlbGxlbnQgc3dmX25vdF9lbXB0eSB0byBhZGQgc3VwcG9ydCBmb3IgY3VzdG9tIGZpZWxkcyBpbiBjb25kaXRpb25hbCBzdGF0ZW1lbnRzIjtzOjQ6ImhlbHAiO3M6NTA6Imh0dHA6Ly9mb3J1bS50ZXh0cGF0dGVybi5jb20vdmlld3RvcGljLnBocD9pZD0yNDgxIjtzOjQ6ImNvZGUiO3M6NTMzOiJmdW5jdGlvbiBjdXN0b21fbm90X2VtcHR5KCRhdHRzLCAkY29udGVudHMpIHsgZ2xvYmFsICR0aGlzYXJ0aWNsZTsgJGlkID0gJHRoaXNhcnRpY2xlWyJ0aGlzaWQiXTsgaWYgKGlzX2FycmF5KCRhdHRzKSkgZXh0cmFjdCgkYXR0cyk7ICR3cmFwdGFnID0gKGVtcHR5KCR3cmFwdGFnKSkgPyAiIiA6ICR3cmFwdGFnOyAkY3VzdG9taWQgPSAoZW1wdHkoJGN1c3RvbWlkKSkgPyAxIDogJGN1c3RvbWlkOyAkY3VzdG9tX2ZpZWxkID0gImN1c3RvbV8iLiRjdXN0b21pZDsgJHJlcyA9IHNhZmVfcm93cygkY3VzdG9tX2ZpZWxkLCJ0ZXh0cGF0dGVybiIsImlkPSckaWQnIik7DQokb3V0ID0gJHJlczxzdXA+PGEgaHJlZj0iI2ZuMCI+MDwvYT48L3N1cD5bJGN1c3RvbV9maWVsZF07IGlmIChpc3NldCgkbWlubGVuZ3RoKSkgeyBpZiAoJG1pbndvcmRzIDwgY291bnQoZXhwbG9kZSgiICIsICRvdXQpKSkgeyByZXR1cm4gcGFyc2UoJGVuY2xvc2VkKTsgfTsgfSBlbHNlaWYoIWVtcHR5KCRvdXQpKSB7IHJldHVybiBwYXJzZSgkY29udGVudHMpOyB9OyI7czozOiJtZDUiO3M6MzI6ImJiMTY5N2Y2ZTc0ZTVmNGUyYzllMTdjMzY2M2NiNjY3Ijt9’
?>

</code>

I’ve not done this before so it may not work.
Lee

Last edited by lee (2004-07-29 16:06:28)

Offline

#19 2004-07-30 00:15:28

jimb
Archived Plugin Author
From: Chicago, IL, USA
Registered: 2004-07-22
Posts: 27
Website

Re: swf_if_empty

Yeah, sorry about that, I should have compiled it. I was just a little uneasy releasing a plugin with my name on it that was basically just a sandwich of two other people’s code.

If anyone has any problems with it let me know, or if there are any features that you want to see. I will add documentation and post a real plugin tonight.

Thanks lee for compiling it by the way- I didn’t check it but I will once I get back from dinner-

Jim

Offline

#20 2004-07-30 00:19:55

swf
Plugin Author
From: Saskatoon, Saskatchewan Canada
Registered: 2004-06-21
Posts: 109
Website

Re: swf_if_empty

I’ll see you in court ;)

Actually I had planned on adding custom fields but wnated to wait to see it the next version had an easier way to access custom fields.

I have a question though What does this line do?
<code>$out = $res<sup><a href=”#fn0”>0</a></sup>[$custom_field];</code>

Last edited by swf (2004-07-30 00:31:33)

Offline

#21 2004-07-30 02:02:03

jimb
Archived Plugin Author
From: Chicago, IL, USA
Registered: 2004-07-22
Posts: 27
Website

Re: swf_if_empty

Um, I’m not sure what happened to that line, but it must have gotten garbled in the copy/paste process- who knows… I’m pretty sure in it’s current state it would throw at least one error. And not work. So that means that lee’s compilation will most likely not function.

In any case, I compiled the plugin and cleaned it up a bit. You can get it here if you cannot wait for the next version of TXP and swf’s plugin.

Last edited by jimb (2004-07-30 02:05:29)

Offline

#22 2004-07-30 07:27:22

nardo
Member
From: tuvalahiti
Registered: 2004-04-22
Posts: 743

Re: swf_if_empty

cheers jimb – champion… works for me

Offline

#23 2004-08-02 21:41:24

kennethlove666
Member
From: arkansas
Registered: 2004-04-27
Posts: 107
Website

Re: swf_if_empty

btw, it’s minlength=“2” not minwords=“2”


Listen to Kenneth

Offline

#24 2005-01-22 05:54:26

lwray
Member
From: Allston, MA
Registered: 2004-12-02
Posts: 21
Website

Re: swf_if_empty

Awesome, thanks lots!

Offline

#25 2005-06-11 23:51:10

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

Re: swf_if_empty

Do you think this plugin could be made to work with comments? As in it will check if someone has inputted a website, then you display one thing, and if they haven’t, then you display another.

That would be really cool.


bludrop studios .::. Creative Expression

Offline

#26 2005-06-12 04:52:25

swf
Plugin Author
From: Saskatoon, Saskatchewan Canada
Registered: 2004-06-21
Posts: 109
Website

Re: swf_if_empty

RE: Comments
I’m not sure if this i can get this plugin to work with comments since I thought they were pretty closed, but now that i have some time, I can work on it to see. Give me a couple days and I’ll see what I can come up with.

If anyone has other suggestions, now would be the time to ask or offer.

Offline

#27 2005-06-12 07:13:32

Andrew
Plugin Author
Registered: 2004-02-23
Posts: 730

Re: swf_if_empty

What are the differences between this plugin and the built-in <txp:if_custom_field />?

Offline

#28 2005-06-12 15:21:20

swf
Plugin Author
From: Saskatoon, Saskatchewan Canada
Registered: 2004-06-21
Posts: 109
Website

Re: swf_if_empty

This one doesn’t work with the custom fields but it does work with the other fields so you can setup a condition that if there is a category2, you can put a coma after category1.

BTW i didn’t realize there was an if_custom_field tag now. I wish there was at least a taglist for txp so I knew what was built-in now

Offline

#29 2005-10-27 17:22:50

-rr-
Member
Registered: 2005-09-11
Posts: 73

Re: swf_if_empty

I can’t seem to get this to work:

<code>
<txp:swf_if_not_empty category1=“Articles” minlength=“0” >
<h5>Articles</h5>
<ul><txp:chh_article_custom category=“Articles” listform=“titleonly” /></ul>
</txp:swf_if_not_empty>
</code>
<br>

will show the <code><h5>Articles</h5></code> title even though it doesn’t contain any articles, when what I’m trying to do is to hide the title if there are no articles.

If I put some articles in the category and up the “minlength” to anything above zero it lists nothing at all ???. Changing the category1 to category2 doesn’t seem to make a difference.

I’m stumped!

Offline

#30 2005-10-28 02:35:03

swf
Plugin Author
From: Saskatoon, Saskatchewan Canada
Registered: 2004-06-21
Posts: 109
Website

Re: swf_if_empty

it looks like you are trying to check the category to see if it has a value of “Articles”. The pugin can only check to see if a field is empty. You can use field=“category1” to check if category1 is empty, but not to see if it has a particular value

Last edited by swf (2005-10-28 02:35:57)

Offline

Board footer

Powered by FluxBB