访问 smarty 变量的名称

发布于 2025-01-09 12:32:49 字数 610 浏览 2 评论 0原文

您好,我需要一些基本问题的帮助。这是我的代码:

{foreach $sArticle.attributes.core->toArray() as $attribute}
                        <tr class="product--properties-row">
                            <td class="product--properties-label is--bold">{$sArticle.attributes.name}{$sArticle.attributesName}</td>
                            <td class="product--properties-label is--bold">{$attribute}</td>
                        </tr>
                    {/foreach}

1.问题:如何输入属性名称?我的意思是数据库中属性的列名? 2.问题:我只想用 foreach 循环遍历 name="artikelattr_" 的列,知道如何做到这一点吗?

谢谢

Hello i need some help with a basic question. This is my code:

{foreach $sArticle.attributes.core->toArray() as $attribute}
                        <tr class="product--properties-row">
                            <td class="product--properties-label is--bold">{$sArticle.attributes.name}{$sArticle.attributesName}</td>
                            <td class="product--properties-label is--bold">{$attribute}</td>
                        </tr>
                    {/foreach}

1.Question: How do I enter the attributes name? I mean the column name from the attribute in the database?
2.Question: I only want to loop with the foreach through columns with name="artikelattr_" any idea how this can be done?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

野稚 2025-01-16 12:32:49

我在这里调整了我的答案:https://stackoverflow.com/a/71237355/7201069
如何获取属性的名称。

要仅考虑以特定字符串开头的某些属性,只需在循环中添加 if

{foreach $sArticle.attributes.core->toArray() as $attributeName => $attribute}
    {if $attributeName|strpos:"artikelattr_" === 0}
        {$attributeName|var_dump}
        {$attribute|var_dump}
    {/if}
{/foreach}

您可以简单地使用 Smarty 中的几乎所有 PHP 函数。

I adjusted my answer here: https://stackoverflow.com/a/71237355/7201069
How to get the name of the attribute.

To consider only certain attributes that starts with a specific string, just add an if in the loop:

{foreach $sArticle.attributes.core->toArray() as $attributeName => $attribute}
    {if $attributeName|strpos:"artikelattr_" === 0}
        {$attributeName|var_dump}
        {$attribute|var_dump}
    {/if}
{/foreach}

You can simply use nearly all PHP functions in Smarty.

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