Opencart 向扩展/模块添加标记
我试图让产品标签显示在特色模块上,事实上,在网站的任何地方!我已经设法让标签发挥作用,但出于某种原因,它只在所有产品上显示一个标签(同一个标签),而不是在每个项目上使用单独的标签 我拥有的每个产品都有自己的标签,只是,相同的标签显示了我输入的位置 在我的featured.php控制器中有:Opencart 向扩展/模块添加标记,opencart,opencart-module,opencart-3,Opencart,Opencart Module,Opencart 3,我试图让产品标签显示在特色模块上,事实上,在网站的任何地方!我已经设法让标签发挥作用,但出于某种原因,它只在所有产品上显示一个标签(同一个标签),而不是在每个项目上使用单独的标签 我拥有的每个产品都有自己的标签,只是,相同的标签显示了我输入的位置 在我的featured.php控制器中有: $data['tags'] = array(); if ($product_info['tag']) { $tags = explode(',', $
$data['tags'] = array();
if ($product_info['tag']) {
$tags = explode(',', $product_info['tag']);
foreach ($tags as $tag) {
$data['tags'][] = array(
'tag' => trim($tag),
'href' => $this->url->link('product/search', 'tag=' . trim($tag))
);
}
}
在我的featured.twig文件中:
{% if tags %}
<p>{{ text_tags }}
{% for i in 0..tags|length %}
{% if i < (tags|length - 1) %} <a href="{{ tags[i].href }}">{{ tags[i].tag }}</a>,
{% else %} <a href="{{ tags[i].href }}">{{ tags[i].tag }}</a> {% endif %}
{% endfor %} </p>
{% endif %}
{%if标记%}
{{text_tags}}
{0..tags | length%}
{%如果i<(标记|长度-1)%},
{%else%}{%endif%}
{%endfor%}
{%endif%}
正如我所说,它只是简单地为每个产品重复相同的标签,而不是使用每个产品自己的标签……我哪里出错了
非常感谢 在featured.php控制器中,找到:
$data['products'][] = array(
替换为:
$product_tags = array();
if ($product_info['tag']) {
$tags = explode(',', $product_info['tag']);
foreach ($tags as $tag) {
$product_tags[] = array(
'tag' => trim($tag),
'href' => $this->url->link('product/search', 'tag=' . trim($tag))
);
}
}
$data['products'][] = array(
'tags' => $product_tags,
并在featured.twig中使用它:
{% if product.tags %}
<p>{% for i in 0..product.tags|length %}
{% if i < (product.tags|length - 1) %} <a href="{{ product.tags[i].href }}">{{ product.tags[i].tag }}</a>,
{% else %} <a href="{{ product.tags[i].href }}">{{ product.tags[i].tag }}</a> {% endif %}
{% endfor %} </p>
{% endif %}
{%if product.tags%}
{0..product.tags中的i为%length%}
{%如果i<(product.tags | length-1)%},
{%else%}{%endif%}
{%endfor%}
{%endif%}
谢谢你,已经修好了!:)