Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#25 2016-09-23 19:45:51

etc
Developer
Registered: 2010-11-11
Posts: 5,192
Website GitHub

Re: Value-optional attributes

ruud wrote #301715:

Why not $attribute = "1", to achieve better compatibility with existing plugins that do strict === comparisons?

Unfortunately, then <txp:if_variable name="test" value>... would not work, since "1"=="some value" is false, while true=="some value" is true.

Last edited by etc (2016-09-23 20:30:48)

Offline

#26 2016-09-24 08:38:40

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Value-optional attributes

etc wrote #301716:

Unfortunately, then <txp:if_variable name="test" value>... would not work, since "1"=="some value" is false, while true=="some value" is true.

But <txp:if_variable name="test"> would work and have the effect you intend while being shorter due to this bit of code:

        if (!isset($atts['value'])) {
            $x = true;
        }

Offline

#27 2016-09-24 09:18:45

etc
Developer
Registered: 2010-11-11
Posts: 5,192
Website GitHub

Re: Value-optional attributes

ruud wrote #301719:

But <txp:if_variable name="test"> would work and have the effect you intend

Not exactly, it would not check for value emptiness.

Offline

#28 2016-09-24 11:40:40

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Value-optional attributes

If you wanted to check for value emptyness, you’d set value="".

Offline

#29 2016-09-24 12:45:25

etc
Developer
Registered: 2010-11-11
Posts: 5,192
Website GitHub

Re: Value-optional attributes

ruud wrote #301726:

If you wanted to check for value emptyness, you’d set value="".

It’s checking for non-emptiness that I wanted to simplify in the OP. $value = true will match any non-empty string, while $value = "1" matches only itself.

Offline

Board footer

Powered by FluxBB