Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Foreach prüfen ob ein Element bereits exisitiert

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
druppandi
Smarty n00b


Joined: 09 Jun 2012
Posts: 2

PostPosted: Sat Jun 09, 2012 3:44 pm    Post subject: Foreach prüfen ob ein Element bereits exisitiert Reply with quote

Hallo,

ich möchte in meinem Shop eine Liste der Hersteller in einem Produktfilter ausgeben.
Nun mache ich die gleiche Foreach Ausgabe im Filterbereich, mit der ich auch die Produkte ausgebe.
Allerdings dürfen hier die Werte nur einmal erscheinen.

So weit bin ich schon:

{foreach name=aussen item=module_data from=$module_content}
{if !isset($item) || $item==''}
<option value="{$module_data.MANUFACTURERS_NAME}">{$module_data.MANUFACTURERS_NAME}</option>
{/if}
{/foreach}

Wie muss die If Abfrage aussehen das jeder Hersteller aus der Liste nur einmal geschrieben wird?

Vielen Dank im Voraus
Andi
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sat Jun 09, 2012 5:05 pm    Post subject: Reply with quote

Code:
{$found = []}
{foreach name=aussen item=module_data from=$module_content}
{if !in_array($module_data.MANUFACTURERS_NAME,$found)}
<option value="{$module_data.MANUFACTURERS_NAME}"{$module_data.MANUFACTURERS_NAME}</option>
{$found[] = $module_data.MANUFACTURERS_NAME}
{/if}
{/foreach}
Back to top
View user's profile Send private message
druppandi
Smarty n00b


Joined: 09 Jun 2012
Posts: 2

PostPosted: Sat Jun 09, 2012 5:25 pm    Post subject: Hmmm Bekomme einen Fehler Reply with quote

Hallo,

danke für die Antwort.

Damit wirft mir das System folgendes aus:

Fatal error: Smarty error: [in led-licht-lampen/module/product_listing/product_listing_v1.html line 113]: syntax error: unrecognized tag: $found[] = $module_data.MANUFACTURERS_NAME (Smarty_Compiler.class.php, line 446) in /kunden/180696_53909/bige20/includes/classes/Smarty_2.6.26/Smarty.class.php on line 1103

So eingebunden:

{$found = []}
{foreach name=aussen item=module_data from=$module_content}
{if !in_array($module_data.MANUFACTURERS_NAME,$found)}
<option value="{$module_data.MANUFACTURERS_NAME}">{$module_data.MANUFACTURERS_NAME}</option>
{$found[] = $module_data.MANUFACTURERS_NAME}
{/if}
{/foreach}
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Sat Jun 09, 2012 5:41 pm    Post subject: Reply with quote

Oh Du arbeitest noch mit Smarty 2. Der Kode arbeitet nur in Smarty 3.

Dann wird's knifflig, da wahrscheinlich die Eintrage eines Herstellers im array nicht unbedingt hintereinander stehen, oder?
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP