Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.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
Css Prestashop 1.6/如何获取承运人id,以便在order-carrier.tpl中使用_Css_Smarty_Prestashop_Var - Fatal编程技术网

Css Prestashop 1.6/如何获取承运人id,以便在order-carrier.tpl中使用

Css Prestashop 1.6/如何获取承运人id,以便在order-carrier.tpl中使用,css,smarty,prestashop,var,Css,Smarty,Prestashop,Var,我正在使用Prestashop 1.6 在order carrier.tpl中,我试图获取carrier id,因为我想在的css类中使用它 例如:div.delivery\u option.carrier\u id\u 33 我试过这个: {$cart->id_carrier} 但是它实际上不起作用。如果它在TPL文件中,您需要首先使用getcontext() 因此,在这种情况下,它将是 {context::getContext()->cart->id_carrier}

我正在使用Prestashop 1.6

在order carrier.tpl中,我试图获取carrier id,因为我想在
的css类中使用它

例如:
div.delivery\u option.carrier\u id\u 33

我试过这个:

{$cart->id_carrier}

但是它实际上不起作用。

如果它在TPL文件中,您需要首先使用getcontext()

因此,在这种情况下,它将是

{context::getContext()->cart->id_carrier}
试试这个代码

<div class="delivery_option {if ($option@index % 2)}alternate_{/if}item {foreach $option.carrier_list as $carrier}carrier_id_{$carrier.instance->id}{/foreach}">


载体不能直接访问,但它们被封装在变量
$option

的后面,但我写这篇文章主要是为了将来参考

首先,模板应该始终有一个全局$carrier smarty变量可用。只要检查一下在你想使用它的地方放置一个
{debug}
标记,看看它是否在那里

第二,不要使用
id\u载体
。这很奇怪,但你会把它弄松的。这不是一个真正可靠的财产。不久前,我与开发人员讨论了这个问题。您应该使用id\u引用:这不会改变

总而言之:

{assign var=carrier_instance value=$carrier.instance}

{* then later somewhere: *}

{$carrier_instance->id_reference}

这就可以了。

因为每当我从smarty搜索id\u引用时,我总是会到这里,所以我会发布我的1.7解决方案

{$carrier_id = context::getContext()->cart->id_carrier.id_reference}

返回carrier\u id\u引用,因为每次修改carrier时carrier\u id都会更改,所以使用carrier操作所需的真实id是id\u引用

try
$carrier.instance->id
,其中变量
$carrier
可用