phpattributesrepeattemplate-talphptal

phptal: how do I repeatedly add attributes?


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>

Solution

  • 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)}