1

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>
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
James Lin
  • 25,028
  • 36
  • 133
  • 233

2 Answers2

0

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)}
Kornel
  • 97,764
  • 37
  • 219
  • 309
0

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>
nickhar
  • 19,981
  • 12
  • 60
  • 73
Chris
  • 1