|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
druppandi Smarty n00b
Joined: 09 Jun 2012 Posts: 2
|
Posted: Sat Jun 09, 2012 3:44 pm Post subject: Foreach prüfen ob ein Element bereits exisitiert |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat Jun 09, 2012 5:05 pm Post subject: |
|
|
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 |
|
druppandi Smarty n00b
Joined: 09 Jun 2012 Posts: 2
|
Posted: Sat Jun 09, 2012 5:25 pm Post subject: Hmmm Bekomme einen Fehler |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Sat Jun 09, 2012 5:41 pm Post subject: |
|
|
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 |
|
|
|
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
|