Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-06-08 20:28:21

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

an attribute named "empty"

Beware: this nasty plastic mannequin strikes again with an idea he got during a sunday satori (probably, to be rejected, as happened with many of his satoris, hehehe).

I’ve been thinking about some kind of tag attribute similar to what chh_if_data does.
This attribute (let’s call it empty) will return something if the tag itself doesn’t return anything.
In other words, if tag returns empty, it really returns the value attribute empty.

Some examples:

<li>Favorite food: <txp:tag name="food" empty="-" /></li> returns <li>Favorite food: - </li> if txp:tag returns empty.

<txp:tag1 empty='<txp:tag2 />' /> (an example using the new parser)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#2 2008-06-08 22:08:54

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

Re: an attribute named "empty"

In cases where you need that, use that plugin. No point in adding such code to each and everytag. That just increases code side and makes it slower.

Offline

#3 2008-06-08 22:25:32

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: an attribute named "empty"

In that case, can we have <txp:if_data>? ;) (Not that I’d want to include each and every plugin in the core, but my impression is that almost everyone is using this one anyway.)

Offline

#4 2008-06-08 22:42:02

redbot
Plugin Author
Registered: 2006-02-14
Posts: 1,410

Re: an attribute named "empty"

Els wrote:

In that case, can we have <txp:if_data>? ;) (Not that I’d want to include each and every plugin in the core, but my impression is that almost everyone is using this one anyway.)

+1

Offline

#5 2008-06-09 06:47:51

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

Re: an attribute named "empty"

I agree with Els. I would also take it a step further and speculate that a lot of “if” tags could be replaced with a more generic tag.

examples could include txp:if_comments, txp:if:excerpt, etc but not txp:if_custom_field as that tag provides flexibility such as:

<txp:if_custom_field name=“url”>
<a href=”<txp:custom_field name=“url” />”><txp:custom_field name=“image” /></a>
</txp:if_custom_field>

>EDIT: Rethinking about it:)

All if tags could eventually be deprecated if the if_data tag becomes a container tag which could be used like <txp:if_data field="any-field">anything goes here</txp:if_data>

Last edited by colak (2008-06-09 07:03:16)


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#6 2008-06-09 09:51:36

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: an attribute named "empty"

<txp:variable name="honeybunny" value='<txp:custom_field name="redridinghood" />' />
<txp:if_variable name="honeybunny">anything goes here</txp:if_variable>

Offline

#7 2008-06-09 12:32:51

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

Re: an attribute named "empty"

hi Robert,

that looks very handy. will the new txp:variable and if_variable tags allow for tags in tags?


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#8 2008-06-09 12:37:48

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: an attribute named "empty"

Sure. Tags as attributes are tag-independent, as this capability is part of the the new tag parser which handles absolutely every tag, be it built-in or provided by a plugin. You could even use <txp:php>...</txp:php> to generate some really complex attribute values, in case the situation requires some math or complex logic.

Offline

#9 2008-06-09 12:46:01

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,306

Re: an attribute named "empty"

Aah, a bright future lies ahead, Honey Bunny! :)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#10 2008-06-27 15:10:23

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: an attribute named "empty"

hi!

wet wrote:

<txp:variable name="honeybunny" value='<txp:custom_field name="redridinghood" />' />
<txp:if_variable name="honeybunny">anything goes here</txp:if_variable>

colak wrote:

that looks very handy. will the new txp:variable and if_variable tags allow for tags in tags?

I know wet’s code is just an example, but isn’t this exactly the same as this?

<txp:if_custom_field name="honeybunny">anything goes here</txp:if_custom_field>

I mean, I can’t see anything “very handy” through that example. Any other example that will make me drop my jaw? :o——[]

Last edited by maniqui (2008-06-27 15:10:39)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#11 2008-06-27 15:15:58

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: an attribute named "empty"

May it’s not about “jaw dropping effects”, but flexibility

<ul id="nav">
<txp:section_list sections="contact,support,library,products" include_default="1" default_title="Home" wraptag="" break="" form="nav2" />
</ul>

nav2

<txp:if_section name='<txp:section />'>
  <txp:variable name="navactive" value="strong" />
<txp:else />
  <txp:variable name="navactive" value="" />
</txp:if_section>
<li>
<txp:section title="1" link="1" wraptag='<txp:variable name="navactive" />' />
<txp:variable name="sec" value='<txp:section />' />
<txp:if_variable name="sec" value="products">
  <txp:category_list section="products" categories="a,b,c" wraptag="ul" break="li" form="nav3" />
</txp:if_variable>
<txp:if_variable name="sec" value="d">
  <txp:section_list sections="library" wraptag="ul" break="li" />
</txp:if_variable>
</li>

nav3

<txp:category link="1" title="1" />
<txp:article_custom section='<txp:section />' category='<txp:category />' sort="Title asc" limit="999" wraptag="ul" break="li">
  <txp:wet_link><txp:custom_field name="menutitle" default='<txp:title />' /></txp:wet_link>
</txp:article_custom>

Offline

#12 2008-06-27 16:36:14

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: an attribute named "empty"

Thanks, wet!
Your example both made me drop my jaw and made it flexible at the same time (it was like a cross to my mandible). I’m still trying to recover…

Lets try to dissect this one too:

<txp:if_variable name="sec" value="products">
<txp:category_list section="products" categories="a,b,c" ... />
</txp:if_variable>

connected with this
<txp:article_custom section='<txp:section />' category='<txp:category />' ...>
means necessarily that section='<txp:section />' returns section='products' (brain overheating)
and being that category='<txp:category /> is context sensitive… (brain about to explode)
mmmm if it returns something different than a, b or c(sticky chunks of brain all over the walls)

OK, I can’t connect categories="a,b,c" with category='<txp:category />
Care to explain, please? :D
——

Let’s go on:

<txp:if_variable name="sec" value="d">
<txp:section_list sections="library" wraptag="ul" break="li" />
</txp:if_variable>

I think I didn’t get this one either.
If there is a section named “d”, the condition will be true and then… it will output a txp:section_list but just with the section “library”?
And, at the same time, this section_list is inside the other section_list?
——

Finally: <txp:custom_field name="menutitle" default='<txp:title />' />
Ooooh! I didn’t know about the default attribute for txp:custom_field!
It’s similar to (or exactly) what I’ve asked when I started this thread (an attribute named “empty”)
Just to be sure:
<txp:custom_field name="menutitle" default='<txp:title />' /> is equal to
<txp:if_custom_field name="menutitle"><txp:custom_field name="menutitle"><txp:else /><txp:title /></txp:if_custom_field />
Right?

Last edited by maniqui (2008-06-27 19:07:57)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB