Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: multiple values for attribute "value" in <txp:if_variable>
smd_if has ya covered.
Offline
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
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
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
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