Jump to content

Add tags to product.tpl


Recommended Posts

  • 4 months later...
  • 1 year later...
  • 5 weeks later...

Seemed that this more

 

Hi vekia!

 

Thanks for the tutorial. 

How can I add category id to the link so that the search is done in the same category that the product is ?

 

Kind Regards

Seems that is more difficult that I first thought. I hired a programmer to implent this. Working fine now

Link to comment
Share on other sites

  • 6 months later...

The tutorial is not complete ... if you have multiple languages, all tags will appear, thats not wanted usually ...

Instead, add this to product.tpl: (prestashop 1.6)
 

<div class="tags_block">Tags: 
<div class="block_content">
    {assign var=tags value=Tag::getProductTags(Tools::getValue('id_product'))}
    {assign var=lang value=intval(Context::getContext()->cookie->id_lang)}
    {foreach from=$tags.$lang item=value}
         <a class="tag_level1 item" target="_blank" href="{$link->getPageLink('search', true, NULL, "tag={$value|urlencode}")}">{$value|escape:html:'UTF-8'}</a>
    {/foreach}
</div>
</div>

We first assign all tags (tags are saved in arrays, each array for one language) to a variable and then another variable for the current user language. Then add all tags for the current language id ...

The style will be like your standard Prestashop styled tags coming from "tags_block" class and "tag_level1 item" classes.

But you can change it to your own CSS if you want ...
 

Edited by Marek_O (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 1 month later...
  • 4 months later...

The tutorial is not complete ... if you have multiple languages, all tags will appear, thats not wanted usually ...

 

Instead, add this to product.tpl: (prestashop 1.6)

 

<div class="tags_block">Tags: 
<div class="block_content">
    {assign var=tags value=Tag::getProductTags(Tools::getValue('id_product'))}
    {assign var=lang value=intval(Context::getContext()->cookie->id_lang)}
    {foreach from=$tags.$lang item=value}
         <a class="tag_level1 item" target="_blank" href="{$link->getPageLink('search', true, NULL, "tag={$value|urlencode}")}">{$value|escape:html:'UTF-8'}</a>
    {/foreach}
</div>
</div>

We first assign all tags (tags are saved in arrays, each array for one language) to a variable and then another variable for the current user language. Then add all tags for the current language id ...

 

The style will be like your standard Prestashop styled tags coming from "tags_block" class and "tag_level1 item" classes.

 

But you can change it to your own CSS if you want ...

 

 

This helped a lot! Browsed the forum for ages before I found this! Thanks!

Link to comment
Share on other sites

  • 3 weeks later...

Is their a way to hide the tags code when No tags are available for a couple products.

Is it something with if argument? Can someone provide the script.

 

Thanks.

 

You can try this. It seems to work in 1.7

<div class="block_content">
    {assign var=tags value=Tag::getProductTags(Tools::getValue('id_product'))}
    {assign var=lang value=intval(Context::getContext()->cookie->id_lang)}
    {if $tags.$lang}
    <div class="tags_block">Tags: 
    {foreach from=$tags.$lang item=value}
         <a class="tag_level1 item" target="_blank" href="{$link->getPageLink('search', true, NULL, "tag={$value|urlencode}")}">{$value|escape:html:'UTF-8'}</a>
    {/foreach}
    {/if}
</div>
</div>
Link to comment
Share on other sites

×
×
  • Create New...