I like the idea, but I think it is antithetical to TAL. You can defer the logic
to php code to define a variable (what I strive to do) or use another template
system that already has this functionality (as XSLT does exactly)
Sent via BlackBerry by AT&T
From: Robert Goldsmith <rgoldsm...@names.co.uk>
Date: Fri, 12 Jul 2013 15:35:03
To: Template Attribute Language for PHP<firstname.lastname@example.org>
Reply-To: Template Attribute Language for PHP <email@example.com>
Subject: [PHPTAL] Conditional attributes
There are many occasions where the decision to set an attribute or what value
and attribute should have is based on quite complex calculations - such as the
state of multiple other variables. When you have multiple of these attributes
you really only have 4 options, none of which are great:
1) Create a lot of defines in order to calculate intermediate values
2) Create lots of tal blocks with conditionals
3) Try to come up with a statement that does what you need through chaining
4) Write a custom tale.
While these just about cope if you have 1 attribute that needs calculating it
becomes much more complex when you have multiple.
I was thinking that in many of these cases it would be convenient to have a new
element called something like <tal:attribute />
The new element would have a required name attribute (which could be variable,
just like normal) and an optional value attribute and would optionally take
content. Like a tal:block and tal:inline, it would have tal:condition and
The behaviour of the element would be to apply its calculated content as an
attribute with the specified name to the first parent object that is output.
Here's a basic example:
The result of this would be:
<div id="wibble" class="ping" />
The following would result in the same:
<tal:attribute name="class" value="string:ping" />
Obviously the simple example is pointless but shows how I'd considered it
working. You'd be able to have as many tal:attribute nodes as you want (with
some sort of handling for repeated names).
By bubbling the assignment of the attributes up to the first parent output
node you could easily apply complex logic to your attributes and keep then
self-contained. The work needed to calculate one attribute would all be bundled
up in the defines and conditionals surrounding it and not mixed in with other
attributes (unless shared, of course).
What do people think?
PHPTAL mailing list
PHPTAL mailing list