Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Prestashop在1中列出2种产品<;李>;_Php_Smarty_Prestashop - Fatal编程技术网

Php Prestashop在1中列出2种产品<;李>;

Php Prestashop在1中列出2种产品<;李>;,php,smarty,prestashop,Php,Smarty,Prestashop,我有一个滑块,它列出了4pr幻灯片 我想添加一个额外的行,这样它将显示2x4产品 为了实现这一目标,我需要列出2种产品公关。 我真的试着去修复它,但是我的代码和我计算产品的方式有问题 请看一看:`{if isset($products)} {include file=“$tpl_dir./breadcrumb.tpl”} {assign var=count value=0} {foreach from=$products item=product name=products}

我有一个滑块,它列出了4
  • pr幻灯片

    我想添加一个额外的行,这样它将显示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>
    <!-`
    
    {foreach from=$products item=product name=products}
    {如果$count==0}
    
  • {/if} {如果$count==1}
  • {/if} {function name='counter2'} {$count+1} {/函数} {/foreach} Smarty不是一种(完整的)编程语言,它是一个模板引擎。有些事情是故意不允许的

    您应该使用smarty提供的道具,这样您就不必使用编程逻辑来实现您的目标

    对于作业,您需要使用特殊的Smarty功能Smarty

    对于smarty计数器,这应该可以工作:
    {counter start=0 skip=1 assign=“count”}
    {foreach from=$products item=product name=products}
    {如果$count==0}
    
  • {/if} {如果$count==1}
  • {/if} {计数器} {/foreach}
    您可能可以检查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>
    
      {foreach from=$products item=product name=products} {如果$smarty.foreach.products.first==true | |$smarty.foreach.products.index%2==0}
    • {/if} {如果$smarty.foreach.products.index%2==1 | |$smarty.foreach.products.last==true}
    • {/if} {/foreach}

    修改前是否可以共享当前模板代码?
    <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>