[英]phptal: how do I repeatedly add attributes?
I got a phptal template question, I have an associative array which contains HTML attribute information, eg 我有一个phptal模板问题,我有一个包含HTML属性信息的关联数组,例如
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>
Sorry, TAL doesn't have construct for this. 抱歉,TAL没有为此的构造。 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)}
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. 而且我知道这是一个旧线程-但是您不能只使用
tal:attributes
似乎恰恰是自动的。 (See http://phptal.org/manual/en/#tal-attributes ) (请参阅http://phptal.org/manual/en/#tal-attributes )
<a tal:attributes="attrs">abc</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.