1

I have an array that have duplicated values, I want to print the value only once no matter how many time it exist on the array.

This is the code that I have:

{foreach item="item" from=$root.page.news.item }
{foreach from=$item.Tags item=tagitem key=kex}
    {$tagitem}
{/foreach}
{/foreach}

This is what it prints right:

kim000kardashian
kim000kardashian
miley000cyrus
miley000cyrus
kim000kardashian
irina000shayk

and this is what I am looking to print

kim000kardashian 
miley000cyrus 
irina000shayk

Is there a way to achieve this only using Smarty Templates? or any way that I can use on the .tpl files?

Thanks in advance

Saymon
  • 510
  • 9
  • 20
  • You must not understand the purpose of a template system. Smnarty is designed as presentation logic. That means html etc. PHP should handle most of the business logic. Smarty can do something that PHP can but that is not what it's for. Output the array appropriately in PHP using builtin functions like array_unique or other methods. It's much easier and nicer. – Panama Jack Jan 30 '14 at 23:39

1 Answers1

2
{foreach item="item" from=$root.page.news.item }
  {foreach from=$item.Tags item=tagitem key=kex}
    {if !$done.$tagitem}
      {$done.$tagitem = 1}
      {$tagitem}
    {/if}
  {/foreach}
{/foreach}

I am not sure it works with all the versions.

Maybe it would be a bit cleaner to call an array_unique() in the php.

Lajos Veres
  • 13,595
  • 7
  • 43
  • 56