phptal:如何重复添加属性?

发布于 2024-09-18 03:57:49 字数 290 浏览 6 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烦人精 2024-09-25 03:57:49

抱歉,TAL 没有这方面的结构。您需要固定属性:

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

或自己生成标签:

 ${structure php:generate_tag(attrs)}

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)}
無心 2024-09-25 03:57:49

上面的答案是正确的 - 你不能“循环属性”

而且我知道这是一个旧线程 - 但你不能只使用 tal:attributes - 看起来它正是有意的自动执行此操作。 (请参阅http://phptal.org/manual/en/#tal-attributes

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

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文