【问题标题】:Hide image in smarty array在 smarty 数组中隐藏图像
【发布时间】:2013-12-04 14:38:28
【问题描述】:

我已经使用 CMS Made Simple 构建了一个网站,它在其模块中使用了许多智能模板。我正在使用一个目录模块,我需要一些帮助。

我需要隐藏数组中的第一个图像(在缩略图和较大版本中)。任何人都可以帮助提供一个解决方案,让它发挥作用。

这是用于显示缩略图和每个缩略图图像的大版本的页面的 smarty 模板。

这是在我的模板中处理数组的 smarty 和 html 示例:

<div class="item_thumbnails">
{section name=ind loop=$image_url_array}

<a href="{$image_url_array[ind]}" rel="zoom-id:zoom" rev="{$image_url_array[ind]}">
<img src="{$image_thumb_url_array[ind]}" title="{$title}" alt="{$title}" /></a>{/section}

</div>

这是 jsfiddle 中的完整代码template code

这就是页面在前端的显示方式:http://www.intricatecreations.co.uk/index.php?page=cascading-flowers

【问题讨论】:

    标签: html smarty


    【解决方案1】:

    “隐藏”是指用 css 隐藏或将其从 html 输出中删除?

    无论如何,你都应该使用 $smarty.section.ind.first:

    删除:

    {section name=ind loop=$image_url_array}
    {if !$smarty.section.ind.first}
    <a href="{$image_url_array[ind]}" rel="zoom-id:zoom" rev="{$image_url_array[ind]}">
    <img src="{$image_thumb_url_array[ind]}" title="{$title}" alt="{$title}" />
    </a>
    {/if}
    {/section}
    

    隐藏:

    {section name=ind loop=$image_url_array}
    <a href="{$image_url_array[ind]}" rel="zoom-id:zoom" rev="{$image_url_array[ind]}" {if $smarty.section.ind.first}style="display:none"{/if}>
    <img src="{$image_thumb_url_array[ind]}" title="{$title}" alt="{$title}" />
    </a>
    {/if}
    {/section}
    

    【讨论】:

    • 太好了!谢谢你。这已经删除了第一个缩略图。我将如何删除或隐藏第一个较大的图像?
    • 删除大图会涉及一些 php 或 javascript 修改,因为您不能简单地删除标签。一种解决方法是将 {$image_1_url} 替换为空/透明图像(即空白.png)。另外,您是否尝试过使用 php 的 array_shift 从数组中删除第一张图像,然后再将其发送给 smarty?
    • 我明白你的意思,但是我对 php 不是很熟悉,所以我不知道去哪里试试这个。
    猜你喜欢
    • 2014-02-18
    • 1970-01-01
    • 1970-01-01
    • 2018-07-02
    • 1970-01-01
    • 2012-04-15
    • 2011-12-02
    • 2014-01-08
    • 2019-05-19
    相关资源
    最近更新 更多