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

Anfänger: Foreach mit Where

 
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
jack0711
Smarty n00b


Joined: 24 Aug 2013
Posts: 3

PostPosted: Sat Aug 24, 2013 9:57 am    Post subject: Anfänger: Foreach mit Where Reply with quote

Hallo, ich bin absoulter Anfänger und habe folgende Frage:

In eines Webshop (Shopware) möchte ich gerne einen bestimmten Eigenschaftswert ausgeben lassen. Mit folgender Funktion lasse ich alles Eigenschaften ausgeben:
Code:
{foreach from=$sArticle.sProperties item=sProperty}
   {$sProperty.name}
        {$sProperty.value}
{/foreach}


Wie kann ich die Foreach Schleife abändern, dass er mir nur einen bestimmten Wert ausgibt. Bspw. sProperty.name = groesse

Bzw. gibt es eine andere Funktion, um nur diesen einen Wert auszugeben?

danke für eure Hilfe
Back to top
View user's profile Send private message
Fahrstuhllicht
Smarty Rookie


Joined: 10 Jun 2013
Posts: 15
Location: Berlin

PostPosted: Sat Aug 24, 2013 11:57 am    Post subject: Reply with quote

Was steckt denn hinter deinem $sarticle.sproperties? Ein Array oder was ?
Wie ist das aufgebaut.
Ggf. reicht es, wenn du noch eine foreachschleife einbaust.
Back to top
View user's profile Send private message Send e-mail
jack0711
Smarty n00b


Joined: 24 Aug 2013
Posts: 3

PostPosted: Sat Aug 24, 2013 12:01 pm    Post subject: Reply with quote

vielen dank für die Antwort. dahinter steckt ein Array mit verschiedenen eigenschaftswerten. ich benötige aber nur die eine Eigenschaft. kannst du ein Beispielcode posten? danke
Back to top
View user's profile Send private message
Fahrstuhllicht
Smarty Rookie


Joined: 10 Jun 2013
Posts: 15
Location: Berlin

PostPosted: Sat Aug 24, 2013 2:54 pm    Post subject: Reply with quote

Es wäre praktisch, wenn du mal nen Print_r von dem Array machst und das postest
Back to top
View user's profile Send private message Send e-mail
U.Tews
Administrator


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

PostPosted: Sat Aug 24, 2013 3:02 pm    Post subject: Reply with quote

Code:
{foreach from=$sArticle.sProperties item=sProperty}
{if $sProperty.name == 'groesse'}
   {$sProperty.name}
        {$sProperty.value}
{/if}
{/foreach}
Back to top
View user's profile Send private message
jack0711
Smarty n00b


Joined: 24 Aug 2013
Posts: 3

PostPosted: Fri Aug 30, 2013 4:08 pm    Post subject: Reply with quote

Vielen Dank für die Antwort. Das hat schon mal geklappt;) Geht es auch einfacher (ohne Schleife)?

Das Array habe ich mal per print_r ausgegeben
Code:
Array ( [1] => Array ( [id] => 1 [optionID] => 1 [name] => Jahrgang [groupID] => 1 [groupName] => Wein [value] => 2011 [valueID] => 5 [nameTranslation] => [groupNameTranslation] => [valueTranslation] => [values] => Array ( [0] => 2011 ) ) [4] => Array ( [id] => 4 [optionID] => 4 [name] => Rebsorte [groupID] => 1 [groupName] => Wein [value] => Cabernet Sauvignon, Merlot, Riesling [valueID] => 14 [nameTranslation] => [groupNameTranslation] => [valueTranslation] => [values] => Array ( [0] => Cabernet Sauvignon [1] => Merlot [2] => Riesling ) ) [3] => Array ( [id] => 3 [optionID] => 3 [name] => Verpackung [groupID] => 1 [groupName] => Wein [value] => Karton [valueID] => 10 [nameTranslation] => [groupNameTranslation] => [valueTranslation] => [values] => Array ( [0] => Karton ) ) [2] => Array ( [id] => 2 [optionID] => 2 [name] => Farbe [groupID] => 1 [groupName] => Wein [value] => rot [valueID] => 1 [nameTranslation] => [groupNameTranslation] => [valueTranslation] => [values] => Array ( [0] => rot ) ) ) 1


Ich möchte nur den Wert für Jahrgang = 2011 ausgeben.
Back to top
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Fri Aug 30, 2013 4:50 pm    Post subject: Reply with quote

Das ginge nur wenn der Key vom Array sProperties immer gleich und bekannt ist. In Deinem Beispiel 1.

Code:
{if $sArticle.sProperties.1.value == 2011}
   {$sArticle.sProperties.1.name} {$sArticle.sProperties.1.value}
{/if}


Für nähre Tipps fehlt der übergeordnet Zusammenhang in dem Du die Ausgabe machen willst.
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