Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: swf_if_empty
I added a minwords parameter to the functions in this plugin I’ll recompile it later when I have a few free minutes but for now i can post the new code here. If you set minwords=“2” it works on textile enabled bodies
<code>
function swf_if_not_empty($atts, $enclosed) {
global $thisarticle;
if (is_array($atts)) {
extract($atts);
};
if (isset($minlength)) {
if ($minlength < count(explode(” “, $thisarticle[$field]))) {
return parse($enclosed);
};
}
elseif(!empty($thisarticle[$field])) {
return parse($enclosed);
};
}
function swf_if_empty($atts, $enclosed) {
global $thisarticle;
if (is_array($atts)) {
extract($atts);
};
if (isset($minlength)) {
if ($minlength >= count(explode(” “, $thisarticle[$field]))) {
return parse($enclosed);
};
}
elseif(empty($thisarticle[$field])) {
return parse($enclosed);
};
}
</code>
Last edited by swf (2004-07-24 18:39:29)
Offline
#14 2004-07-25 04:22:41
- nardo
- Member
- From: tuvalahiti
- Registered: 2004-04-22
- Posts: 743
Re: swf_if_empty
swf – can I request custom fields to be included in your next version? : )
cheers
Offline
Offline
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”];
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=‘YTo4OntzOjQ6Im5hbWUiO3M6MjA6ImppbV9jdXN0b21fbm90X2VtcHR5IjtzOjY6ImF1dGhvciI7czo1OiJKaW0gQiI7czoxMDoiYXV0aG9yX3VyaSI7czoyNzoiaHR0cDovL2lu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VtcHR5KCRvdXQpKSB7IHJldHVybiBwYXJzZSgkY29udGVudHMpOyB9OyI7czozOiJtZDUiO3M6MzI6ImJiMTY5N2Y2ZTc0ZTVmNGUyYzllMTdjMzY2M2NiNjY3Ijt9’
?>
</code>
I’ve not done this before so it may not work.
Lee
Last edited by lee (2004-07-29 16:06:28)
Offline
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
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
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
Re: swf_if_empty
btw, it’s minlength=“2” not minwords=“2”
Listen to Kenneth
Offline
Re: swf_if_empty
Awesome, thanks lots!
Offline