Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Value-optional attributes
I’m playing with the parser (again) and thinking aloud: wouldn’t it be loverly to be able to write just <txp:section title link />
instead of <txp:section title="1" link="1" />
and
<txp:if_variable name="test" value>...</txp:if_variable>
instead of
<txp:if_variable name="test" value=""><txp:else />...</txp:if_variable>
It’s just a matter of tweaking few parser regexps and assigning true
to valueless attributes (tested, works).
Online
Re: Value-optional attributes
/me jumps up and down in excitement on the sidelines shouting ‘ra ra ra’!
I like the sound of that. Especially the shortened <txp:if_variable>
construct.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Value-optional attributes
Offline
Re: Value-optional attributes
Bloke wrote #301670:
/me … on the sidelines
Ha ha, Stef looking for new feelings. Let’s do it then, the only risk I see is that one was not able to assign attr=true
(Boolean) before. If some plugin uses this value internally to do weird things, trouble can happen, though I don’t really see how.
NicolasGraph wrote #301671:
It would; definitely! I even thought that It was already possible in the past…
Ah yes, I remember now. And yes, it would be invalid XML, but txp is invalid XML anyway (tags in tags).
May I ask forum admins to merge these topics if possible? Thanks!
Last edited by etc (2016-09-22 13:17:08)
Online
Re: Value-optional attributes
etc wrote #301672:
If some plugin uses
attr=true
internally to do weird things, trouble can happen.
I don’t know of any that are in current production. Most adhere to the quoted attribute system.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Value-optional attributes
Bloke wrote #301673:
I don’t know of any that are in current production. Most adhere to the quoted attribute system.
In my mkp_gravatar plugin, I decided to make it easy for everyone:
extract(lAtts(array(
'secure' => '0',
),$atts));
$url = ($secure=='1' || $secure=='y' || $secure=='true') ? 'https://secure.gravatar.com/avatar/' : 'http://www.gravatar.com/avatar/';
Personally, I would love to see this because I always hate to test for null conditions. I think it makes the code much less readable.
Offline
Online
Re: Value-optional attributes
etc wrote #301672:
May I ask forum admins to merge these topics if possible? Thanks!
Hi Oleg, merging topivs is unfortunately impossible since this forum was updated.
Also… as you are working on the code, I think that we should make you a developer. :)
Last edited by colak (2016-09-22 14:24:53)
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: Value-optional attributes
Would the existing sites still work with the changes to the parse or should we go through the tags and change them?
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: Value-optional attributes
michaelkpate wrote #301676:
Personally, I would love to see this because I always hate to test for null conditions. I think it makes the code much less readable.
Yes, just <txp:mkp_gravatar secure />
should work.
colak wrote #301679:
Also… as you are working on the code, I think that we should make you a developer. :)
Hi Yiannis, I’m only a dev-apprentice, them Big Devs said “take the keys and don’t disturb us” :)
Would the existing sites still work with the changes to the parse …?
Certainly, at least I hope so. You can still use <txp:tag attr="1" />
scheme if necessary.
Online
Re: Value-optional attributes
Yay! I have a shit metric funk-ton of <txp:if_something value=""><txp:else/></txp:if_something>
I have also had mixed results with conditionals testing for “unset” vs “set but empty” how would the new structure relate to that?
[edited for metric conversion]
Offline
Re: Value-optional attributes
etc,
I was actually referring to your original example:
<txp:if_variable name="test" value=""><txp:else />...</txp:if_variable>
It doesn’t bother me in PHP as much as it does with TXP Tags.
Offline