2017-07-20 65 views
0

我想检查产品是否有特定标签。如果是这样,我想显示一些文字。以下是我所做的一些示例。有用。唯一的问题是我得到错误。检查产品是否在Prestashop中有特定标签1.6.1.4

{if in_array('rent', $product->tags.1)} 
     <img id="turnKeyimg" alt="TurnKey Rental Option" src="{$tpl_uri}img/key.png"/> 
     <h3>TurnKey Rental Option</h3> 
     <p>Also available for immediate rental.<br />Request a quote today</p> 
{/if} 

错误日志有这样的条目:

警告:in_array()预计参数2为阵列,在/cache/smarty/compile/94/4d/52/944d5284e871d0de7a0c6b84ebb2089ad579ed8b.file空给出.product.tpl.php在高速缓存行330

线330看起来是这样的:

<?php if (in_array('rent',$_smarty_tpl->tpl_vars['product']->value->tags[1])) {?> 
    <img id="turnKeyimg" alt="TurnKey Rental Option" 
    src="<?php echo $_smarty_tpl->tpl_vars['tpl_uri']->value; 
?> 

我做了什么错了导致这些错误?

回答

0

要修复错误消息,我添加了一个检查数组是否存在。没有更多的错误。

{if (isset($product->tags) && $product->tags)} 
    {if in_array('rent', $product->tags.1)} 
     <img id="turnKeyimg" alt="TurnKey Rental Option" src="{$tpl_uri}img/key.png"/> 
     <h3>TurnKey Rental Option</h3> 
     <p>Also available for immediate rental.<br />Request a quote today</p> 
    {/if} 
{/if} 
0

警告:in_array()预计参数2是阵列,在...

简单空给出in_array()函数需要第二个参数是一个数组,但你传递NULL为第二论据。

您必须首先检查$_smarty_tpl->tpl_vars['product']->value->tags[1]是否为数组,然后执行in_array(...)操作。

<?php if (is_array($_smarty_tpl->tpl_vars['product']->value->tags[1]) && in_array('rent',$_smarty_tpl->tpl_vars['product']->value->tags[1])) {?> 
    <img id="turnKeyimg" alt="TurnKey Rental Option" 
    src="<?php echo $_smarty_tpl->tpl_vars['tpl_uri']->value; 
?> 
+0

这个用smarty怎么看?我不能使用<?php。 我试过了:{if(is_array($ _ smarty_tpl-> tpl_vars ['product'] - > value-> tags [1])&& in_array('rent',$ _ smarty_tpl-> tpl_vars ['product'] - > value - > tags [1]))}但该检查不再有效。我查看了一个标签出租的产品,我想要显示的文本没有显示。 – N13Design

+0

@ N13Design我不是Smarty模板的专家,但是您是否尝试了这种方法,[https://pastebin.com/ZBy4eNJe](https://pastebin.com/ZBy4eNJe)? –

+0

Prestashop里面有些东西不喜欢。它打破了页面。 – N13Design

相关问题