0

我有一个列出 4 的滑块

  • 公关幻灯片。

    我想添加一个额外的行,以便显示 2x4 产品。

    为了实现它,我需要列出 2 个产品公关。

  • 我真的尝试过修复它,但我的代码和我如何计算我的产品有问题。

    请看一下:`{if isset($products)} {include file="$tpl_dir./breadcrumb.tpl"} {assign var=count value=0}

        {foreach from=$products item=product name=products}
    
            {if $count == 0}
                <li style="position: relative;">
            {/if}
                <div id="ProductCon">
                    <div class="prodimage"><a href="{$product.link|escape:'htmlall':'UTF-8'}" class="product_img_link" title="{$product.name|escape:'htmlall':'UTF-8'}"><img src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'home')}" alt="{$product.legend|escape:'htmlall':'UTF-8'}" {if isset($homeSize)} width="{$homeSize.width}" height="{$homeSize.height}"{/if} /></a></div>
                    <h3><a href="{$product.link|escape:'htmlall':'UTF-8'}" title="{$product.name|escape:'htmlall':'UTF-8'}">{$product.name|truncate:35:'...'|escape:'htmlall':'UTF-8'}</a></h3>
                </div>
                {if $count == 1}
                    </li>
                {/if}
                {function name='counter2'}
                    {$count+1}
                {/function}
        {/foreach}
    
    
    
        </ul>
    </div>
    <!-`
    
  • 4

    2 回答 2

    0

    Smarty 不是(完整的)编程语言,它是一个模板引擎。有些事情是故意不允许的。

    您应该使用作为smarty 提供的道具的计数器,以便您不必使用编程逻辑来实现您的目标。

    对于分配,您需要使用特殊的 Smarty 功能 smarty assign

    对于 smarty 计数器,这应该有效:

    {counter start=0 skip=1 assign="count"}
    
    {foreach from=$products item=product name=products}
        {if $count == 0}
            <li style="position: relative;">
         {/if}
        <div id="ProductCon">
            <div class="prodimage">
                <a href="{$product.link|escape:'htmlall':'UTF-8'}" class="product_img_link" title="{$product.name|escape:'htmlall':'UTF-8'}">
                    <img src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'home')}" alt="{$product.legend|escape:'htmlall':'UTF-8'}" {if isset($homeSize)} width="{$homeSize.width}" height="{$homeSize.height}"{/if} />
                </a>
            </div>
            <h3>
                <a href="{$product.link|escape:'htmlall':'UTF-8'}" title="{$product.name|escape:'htmlall':'UTF-8'}">{$product.name|truncate:35:'...'|escape:'htmlall':'UTF-8'}</a>
            </h3>
        </div>
        {if $count == 1}
            </li>
        {/if}
        {counter}
    {/foreach}
    
    于 2012-08-21T14:25:06.010 回答
    0

    您可能可以检查 foreach 循环中的索引值。这是一个如何实现它的示例。这还会检查列表是否包含奇数个产品并关闭最后一个产品的 li 标签。希望这可以帮助

    <ul>
        {foreach from=$products item=product name=products}
            {if $smarty.foreach.products.first == true || $smarty.foreach.products.index % 2 == 0}
                <li style="position: relative;">
            {/if}
                <div id="ProductCon">
                    <div class="prodimage"><a href="{$product.link|escape:'htmlall':'UTF-8'}" class="product_img_link" title="{$product.name|escape:'htmlall':'UTF-8'}"><img src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'home')}" alt="{$product.legend|escape:'htmlall':'UTF-8'}" {if isset($homeSize)} width="{$homeSize.width}" height="{$homeSize.height}"{/if} /></a></div>
                    <h3><a href="{$product.link|escape:'htmlall':'UTF-8'}" title="{$product.name|escape:'htmlall':'UTF-8'}">{$product.name|truncate:35:'...'|escape:'htmlall':'UTF-8'}</a></h3>
                </div>
            {if $smarty.foreach.products.index % 2 == 1 || $smarty.foreach.products.last == true}
                </li>
            {/if}
        {/foreach}
    </ul>
    
    于 2012-08-21T14:27:37.827 回答