phptal: how do I repeatedly add attributes?

461 Views Asked by At

I got a phptal template question, I have an associative array which contains HTML attribute information, e.g.

attrs['href'] = 'www.google.com';
attrs['id'] = 'the_link';
...

Is there a way to use the "repeat" to loop through my array and generate the attributes dynamically? (I know how to do it statically)

so I can have

<a href="www.google.com" id="the_link">abc</a>
2

There are 2 best solutions below

2
On BEST ANSWER

Sorry, TAL doesn't have construct for this. You'll need fixed attributes:

tal:attributes="href attrs/href | nothing; id attrs/id | nothing"

or generate the tag yourself:

 ${structure php:generate_tag(attrs)}
0
On

Answer above is right -- you can't "loop through attributes"

And I know this is an old thread -- but couldn't you just use tal:attributes -- it seems like it's exactly intended for this automatically. (See http://phptal.org/manual/en/#tal-attributes)

<a tal:attributes="attrs">abc</a>