phptal:如何重复添加属性?
我有一个 phptal 模板问题,我有一个包含 HTML 属性信息的关联数组,例如,
attrs['href'] = 'www.google.com';
attrs['id'] = 'the_link';
...
有没有办法使用“重复”循环遍历我的数组并动态生成属性? (我知道如何静态地做到这一点)
所以我可以
<a href="www.google.com" id="the_link">abc</a>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
抱歉,TAL 没有这方面的结构。您需要固定属性:
或自己生成标签:
Sorry, TAL doesn't have construct for this. You'll need fixed attributes:
or generate the tag yourself:
上面的答案是正确的 - 你不能“循环属性”
而且我知道这是一个旧线程 - 但你不能只使用
tal:attributes
- 看起来它正是有意的自动执行此操作。 (请参阅http://phptal.org/manual/en/#tal-attributes )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)