Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2016-09-22 11:15:32

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

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).

Offline

#2 2016-09-22 11:55:28

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

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

#3 2016-09-22 12:15:42

NicolasGraph
Plugin Author
From: France
Registered: 2008-07-24
Posts: 860
Website

Re: Value-optional attributes

etc wrote #301669:

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" />

It would; definitely! I even thought that It was already possible in the past…


Nicolas
Follow me on Twitter and GitHub!
Multiple edits are usually to correct my frenglish…

Offline

#4 2016-09-22 12:56:04

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

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)

Offline

#5 2016-09-22 12:59:34

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,269
Website GitHub

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

#6 2016-09-22 13:56:19

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

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

#7 2016-09-22 14:06:40

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

Re: Value-optional attributes

Landed in the dev branch, for braves.

Offline

#8 2016-09-22 14:23:16

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,011
Website GitHub Mastodon Twitter

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

#9 2016-09-22 14:26:35

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,011
Website GitHub Mastodon Twitter

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

#10 2016-09-22 15:20:05

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

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.

Offline

#11 2016-09-22 15:30:38

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

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

#12 2016-09-22 15:41:33

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

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

Board footer

Powered by FluxBB