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,383
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: Vöcklabruck, Austria
Registered: 2005-06-06
Posts: 3,416
Website GitHub 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,383
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: Vöcklabruck, Austria
Registered: 2005-06-06
Posts: 3,416
Website GitHub 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,316

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: Vöcklabruck, Austria
Registered: 2005-06-06
Posts: 3,416
Website GitHub 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

#13 2008-06-27 20:32:52

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

Re: an attribute named "empty"

A true jawbreaker, Robert ;)

I think

<txp:variable name="sec" value='<txp:section />' />
<txp:if_variable name="sec" value="products">

is the same as

<txp:if_section name="products" />

Why did you solve it this way? What other ways are there to fill in variables’ values?

The whole variable stuff is rather unseizable for mere mortals without coding background like (Maniqui and) me, as long as we don’t have a clue of what they contain, which vars are accessible (PHP vars also?), when their content can be captured, and when it is disappeared. I’d really appreciate if the variable tags will be documented detailled and all-embracing.

Maniqui, I can really understand your <sup>-comments ;) It just seems that you understood, what I didn’t get. Your sum up helped me a lot, so I now can smartly ask dumb questions ;) and help you a little with this one: In your middle part you mistook txp:variable for txp:section_list. So I think that <txp:if_variable name="sec" value="d">could be achieved with another txp:if_section, right? But right now you’ll have stuffed your mashed brain back where it belongs, so you won’t need this :)


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

Offline

#14 2008-06-28 05:42:49

wet
Developer Emeritus
From: Vöcklabruck, Austria
Registered: 2005-06-06
Posts: 3,416
Website GitHub Mastodon

Re: an attribute named "empty"

maniqui wrote:

<txp:if_variable name=“sec” value=“products”>
<txp:category_list section=“products” categories=“a,b,c” … />
</txp:if_variable></pre>

connected with this
<txp:article_custom section='<txp:section />' category='<txp:category />' ...>
means necessarily that section='<txp:section />' returns section='products' (brain overheating)

True.

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

Important, new in 4.0.7: <txp:category /> is context sensitive. In the context of processing a <txp:category_list />, it returns the “current” category as indicated by the list. Contrast this with a page context where it returns the category for the current page (i.e. the one dervied from the page’s URL).

categories="a,b,c" is fed into category_list, so category_list produces tree list items. In each single list item <txp:category /> uses the “current” list context, so it returns a for the first list item, b for the second, c for the third in this snippet:

<txp:article_custom section='<txp:section />' category='<txp:category />' ...>

This builds three ULs of permlinks to articles in the products section, one for each of the categories. I could have written this with a literall section name instead of '<txp:section />', but it is expandable to more than one section this way by adding more section names to the driving tag <txp:article_custom section='<txp:section />'

Output:

  • Products section
    • Cars category 'a'
      • Alfa Romeo Mito
      • Volvo C30
      • Fiat Cinquecento
    • Planes category 'b'
      • Boeing 777
      • Airbus 350
      • Cessna 172
    • Bikes category 'c'
      • Rotwild
      • Schwab
      • You Get The Picture…

<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?

You got it. I admit that this sample wasn’t carefully crafted for educational purposes, but taken from one of my “real life” sites with a somehow slanted nav structure.

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?

Perfectly right. I think, this is a simple, yet fine exhibit of attribute parsing and how tight you can code with this new capability.

=

uli wrote:

A true jawbreaker, Robert ;)

I think

<txp:variable name=“sec” value=’<txp:section />’ />
<txp:if_variable name=“sec” value=“products”>

is the same as

<txp:if_section name=“products” />

No, not in this case (New in 4.0.7).

  1. This is taken from the nav2 form, which is the markup template for the first-tier menu driven by a txp:section_list.
  2. NB: It’s the “single item tags” as txp:section and txp:category which are context sensitive, not the corresponding conditional tags (txp:if_category, txp:if_section). Otherwise, you could never test for “active as per the URL” sections, categories in a list.
  3. Result: if_section tests whether the current URL points to products, while txp:section return the current txp:section_list item. The second is what I wanted to achieve with storing the txp:section value in a variable and subsequently test the variables value. txp:variable is used as a “Swiss Army Knife” to pull values from almost any source and use these in a conditional test.

Offline

#15 2008-06-28 07:17:10

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

Re: an attribute named "empty"

Just when I was recovering from a broken jaw and an exploded brain… I stepped over wet floor…

wet wrote:

Important, new in 4.0.7: <txp:category /> is context sensitive. In the context of processing a <txp:category_list />, it returns the “current” category as indicated by the list. Contrast this with a page context where it returns the category for the current page (i.e. the one dervied from the page’s URL).

Ok. When in my post I wrote “context sensitive”, I was talking in the now ‘old’ sense of the expression.
If I will try to summary the “sensitive contexts” we already have on 4.0.6 (and previous):

  • page/url context sensitive for: <txp:section />, <txp:category />
  • individual-article/article-list context sensitive for: <txp:article />, <txp:section /> (and also, <txp:section /> is “article-form” sensitive, if used inside a form being rendered on an article list, right?)

Now (4.0.7), we also have, this new “sensitive” context:

  • tag context sensitive: <txp:section />, <txp:category /> (very similar to the “article-form” context sensitive I listed above for <txp:section />)

Am I going well? I hope.
But… (yes, wet already stated, the example wasn’t carefully crafted for educational purposes)

wet wrote:

<txp:article_custom section='<txp:section />' category='<txp:category />' ...>

This builds three ULs of permlinks to articles in the products section, one for each of the categories. I could have written this with a literall section name instead of '<txp:section />', but it is expandable to more than one section this way by adding more section names to the driving tag <txp:article_custom section='<txp:section />'

If <txp:section /> now is tag context sensitive, I may have spotted a mistake in wet’s explanation above, or I may not have understand him. Let’s see.

First question/thing-to-notice: look the code above (<txp:article_custom section='<txp:section />' ...>).
There, section='<txp:section />' is being page/url sensitive or tag-context sensitive?
If I get it right, there, txp:section is being tag-context sensitive.

But wet explained: “but it is expandable to more than one section this way by adding more section names to the driving tag <txp:article_custom section='<txp:section />'

There is where I think I spotted an error in the explanation:
Isn’t the driving tag this one: <txp:category_list section="products" categories="a,b,c" ... />? If not, then I don’t get it yet :)
But if indeed it is the driving tag, wet said:
is expandable to more than one section this way by adding more section names

Is that last statement correct? If yes, then I get that section attribute on <txp:category_list /> can receive more than one value. Like this:
<txp:category_list section="products, library, support">

But does that last one work/make-sense? Only if now <txp:category_list /> can also iterate over values for section (singular) attribute.

Output […]

Nice! And putting the output made everything clearer.

New in 4.0.7

  1. NB: It’s the “single item tags” as txp:section and txp:category which are context sensitive, not the corresponding conditional tags (txp:if_category, txp:if_section). Otherwise, you could never test for “active as per the URL” sections, categories in a list.
  2. Result: if_section tests whether the current URL points to products, while txp:section return the current txp:section_list item. The second is what I wanted to achieve with storing the txp:section value in a variable and subsequently test the variables value. txp:variable is used as a “Swiss Army Knife” to pull values from almost any source and use these in a conditional test.

Great. This explanation worked better for me.
I suggest again to create some “official” nomenclature for naming different “context sensitive” possibilites.
As I suggested above, some names that make sense for me:

  • page/url context sensitive
  • individual-article/article-list context sensitive
  • tag context sensitive (the new one on 4.0.7)

BTW, many thanks, wet!!!

Last edited by maniqui (2008-08-16 22:54:33)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB