Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2009-09-07 19:57:05

jstubbs
Moderator
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: What are your use-cases for the txp:yield tag?

May I ask one of you to write a TXP Tip on the usage of this tag – I’d like to understand it better myself ;-)

Offline

#14 2009-09-07 20:55:57

artagesw
Member
From: Seattle, WA
Registered: 2007-04-29
Posts: 227
Website

Re: What are your use-cases for the txp:yield tag?

Julián,

You make some nice points, but I have reservations.

The yield tag was designed for the simple case of injecting variable content into forms. There is nothing that yield can do that cannot also be accomplished with the variable tag. However, as you say, non-programmers can find the concept of variables confusing, so the yield tag was designed to be a more targeted and narrow way of achieving a very specific use case of the variable tag without burdening non-programmers with the more esoteric issues of naming, scope and collisions that normally accompany variables.

The thing is, once you begin naming yields, there is no longer any disguising the fact that they are in fact variables, at which point you need to start thinking about all the aforementioned issues. So, in my opinion, once you decide to head down that path (due to more complex needs, etc.) it is best to simply embrace variables and learn how to use them properly in those cases where they are required.

I don’t think that variables are necessarily “less readable” if you use them and scope them properly. For instance, your example could be rewritten as follows, which makes it quite clear where the variables will be used:

<txp:output_form name="header">
  <txp:variable name="A">
    Blah blah
    Blah
  </txp:variable>
  <txp:variable name="B">
    Blah
  </txp:variable>
</txp:output_form>
<!DOCTYPE ...>
<head>
  <txp:variable name="A" />
  <txp:variable name="B" />
</head>

Using a scope tag, though not required, will further ensure that no outer instances of these variables are overwritten:

<txp:output_form name="header">
  <txp:scope local="true">
    <txp:variable name="A">
      Blah blah
      Blah
    </txp:variable>
    <txp:variable name="B">
      Blah
    </txp:variable>
  </txp:scope>
</txp:output_form>

Last edited by artagesw (2009-09-07 21:08:47)

Offline

#15 2009-09-07 21:13:23

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

Re: What are your use-cases for the txp:yield tag?

Why add <txp:scope /> to TXP core instead of releasing it as a plugin?
It’s a tag that very few people will actually use, because only programmers understand it’s meaning.
By releasing it as a plugin, the code and functionality can mature better (as part of a release you have only a limited amount of users actually testing new stuff from SVN and making changes after release is often a problem due to backward compatibility requirements).

Offline

#16 2009-09-07 21:17:22

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

Re: What are your use-cases for the txp:yield tag?

Hi Sam,

thanks again.
Yes, your example is something I thought about but didn’t want to add it to my previous post, to make it shorter and as to see what you’ve got under the sleeves. :)

Also, you are right, named yields are somehow just a wrapper around the txp:variable, with the “advantage” of auto-scope/auto-destruction-after-usage/no-name-clashing, which make its easier to mentally grasp them.

Back to your example:

Surrounding the first block with a scope tag, though not required, will further ensure that no outer instances of these variables are overwritten.

This is where I get confused (and where I grapple/cling on the idea of named yields as an easier way), although I’ve to re-read again all the txp:scope info you already posted..

Edit: ok, Sam already replied the below questions (on his post above) while I was writing them.

Let me try to finish your example.
Is it this way?

<txp:output_form name="header">
  <txp:scope local="true">
	<txp:variable name="A">
	Blah blah
	Blah
	</txp:variable>
	<txp:variable name="B">
	Blah
	</txp:variable>
  </txp:scope>
</txp:output_form>

Or this way?

<txp:scope local="true"> 
  <txp:output_form name="header">
	<txp:variable name="A">
	Blah blah
	Blah
	</txp:variable>
	<txp:variable name="B">
	Blah
	</txp:variable>
  </txp:output_form>
 </txp:scope>

Last edited by maniqui (2009-09-07 21:18:54)


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#17 2009-09-07 21:29:36

artagesw
Member
From: Seattle, WA
Registered: 2007-04-29
Posts: 227
Website

Re: What are your use-cases for the txp:yield tag?

ruud wrote:

Why add <txp:scope /> to TXP core instead of releasing it as a plugin?

<txp:scope /> affects the behavior of <txp:variable /> and friends. Until plugins attain the ability to override core tags, the only way to implement <txp:scope /> as a plugin would be to also implement alternate plugin versions of <txp:variable />, <txp:if_variable />, etc. This in turn means changing a bunch of existing code in one’s pages and forms in order to add scoping. And then changing it back again later if <txp:scope /> were eventually added to core.

Offline

#18 2009-09-07 21:31:28

artagesw
Member
From: Seattle, WA
Registered: 2007-04-29
Posts: 227
Website

Re: What are your use-cases for the txp:yield tag?

Julián,

Your two examples are equivalent.

Offline

#19 2009-09-07 22:14:46

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

Re: What are your use-cases for the txp:yield tag?

artagesw wrote:

<txp:scope /> affects the behavior of <txp:variable /> and friends. Until plugins attain the ability to override core tags, the only way to implement <txp:scope /> as a plugin would be to also implement alternate plugin versions of <txp:variable />, <txp:if_variable />, etc. This in turn means changing a bunch of existing code in one’s pages and forms in order to add scoping. And then changing it back again later if <txp:scope /> were eventually added to core.

A good argument against having <txp:variable /> in core ;)

Offline

#20 2009-09-07 23:01:05

artagesw
Member
From: Seattle, WA
Registered: 2007-04-29
Posts: 227
Website

Re: What are your use-cases for the txp:yield tag?

ruud wrote:

A good argument against having <txp:variable /> in core ;)

I was going to make that very point. Your arguments apply equally to <txp:variable /> (itself a programmer-centric tag). Of course, <txp:variable /> is already in core and predates my joining the dev team…

Offline

Board footer

Powered by FluxBB