Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2011-03-23 22:01:42

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

Re: multiple values for attribute "value" in <txp:if_variable>

smd_if has ya covered.

Offline

#14 2011-03-24 00:49:04

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
Website

Re: multiple values for attribute "value" in <txp:if_variable>

Cool, thanks citizens! I installed smd_if earlier today and got it working flawlessly.

Offline

#15 2012-01-24 08:25:54

makss
Plugin Author
From: Ukraine
Registered: 2008-10-21
Posts: 355
Website

Re: multiple values for attribute "value" in <txp:if_variable>

wet wrote:

<txp:if_variable name="foo" value="oh\,my,dear,darling">
tests for either "oh,my", "dear", or "darling"

Maybe add separator ?

<txp:if_variable name="foo" value="oh,my@@dear@@darling" separator="@@">

patched if_variable

        function if_variable($atts, $thing = NULL)
        {
                global $variable;
                extract(lAtts(array(
                        'name'  => '',
                        'value' => '',
                        'separator' => ''         // add this line
                ), $atts));
                if (empty($name))
                {
                        trigger_error(gTxt('variable_name_empty'));
                        return;
                }
                if (isset($variable[$name]))
                {
                        if (!isset($atts['value']))
                        {
                                $x = true;
                        }
                        else
                        {
//                              $x = $variable[$name] == $value;              // change this line
                                $x = ($separator !='') ? in_list($variable[$name], $value, $separator) : $variable[$name] == $value;
                        }
                }
                else
                {
                        $x = false;
                }
                return parse(EvalElse($thing, $x));
        }

upd: fixed, thanks Gocom

Last edited by makss (2012-01-24 11:33:32)


aks_cron : Cron inside Textpattern | aks_article : extended article_custom tag
aks_cache : cache for TxP | aks_dragdrop : Drag&Drop categories (article, link, image, file)

Offline

#16 2012-01-24 10:58:59

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: multiple values for attribute "value" in <txp:if_variable>

That is true, and neat. I think we all are aware that one could use a user-definable separator. But to voice my opinion, I have to say, please no. Textpattern’s tag attributes selection is disordered enough as it is. Every conditional tag shouldn’t have their own syntax, but the parser should handle array of values, and every conditional tag should behave exactly the same way. I.e.

<txp:if_variable name="flavor" in:value="strawberry" in:value="blueberry" in:value="chocolate">
	No tea?
</txp:if_variable>

About the patched if_variable itself, it has minor issues. It doesn’t support empty characters (including 0) as separators. For example this fails:

<txp:if_variable name="flavor" value="1011" separator="0">
	Binary doesn't taste good.
</txp:if_variable>

I would personally set the separator NULL and then check whether it’s set. Also consider white-space, which is an issue when values are listed in a single attribute, instead of as an array of attributes. Unlike custom fields, variables are not neatly organized single line of text.

Offline

#17 2012-01-24 20:15:35

CeBe
Plugin Author
From: Caen - Fr
Registered: 2010-06-25
Posts: 345
Website

Re: multiple values for attribute "value" in <txp:if_variable>

Check cbe_if_variable. It works with a list of value, or like if_custom_field (with a pattern) if you prefer.

Offline

Board footer

Powered by FluxBB