|
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 |
jav664 Smarty Rookie
Joined: 04 Mar 2011 Posts: 11
|
Posted: Fri Mar 04, 2011 5:32 pm Post subject: smarty-first steps: statt foreach auf eine variable gezielt |
|
|
hallo community,
ich bin neu in sachen smarty und hänge gleich mal fest.
hier, dieser codeschnipsel:
Code: |
{foreach name=Attribute from=$Artikel->Attribute item=Attribut}
<p><b>{$Attribut->cName}:</b> {$Attribut->cWert}</p>
{/foreach}
|
funktioniert wunderbar. nun will ich ohne foreach auf eine bestimmte variable zugreifen...
z.B. so
Code: | {if $Artikel->Attribute->cName == "farbe" && $Artikel->Attribute->cWert == "blau"}
mache dies und das
{/if} |
geht nicht. und das:
Code: | {if $Artikel->Attribute->farbe == "blau"}
mache dies und das
{/if} |
geht auch nicht. ich steh auf dem schlauch... |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Fri Mar 04, 2011 6:00 pm Post subject: |
|
|
$Artikel->Attribute scheint ein Array zu sein.
Du musst also einen Index kennen auf den Du zugreifen willst.
$Artikel->Attribute[$index]->cname
Dein Problem ist jetzt das Du nicht weisst unter welchem Index im Array cName = 'farbe' ist. Richtig? |
|
Back to top |
|
jav664 Smarty Rookie
Joined: 04 Mar 2011 Posts: 11
|
Posted: Fri Mar 04, 2011 6:12 pm Post subject: |
|
|
exakt.
allerdings hat das array nur einen eintrag...bis jetzt. |
|
Back to top |
|
jav664 Smarty Rookie
Joined: 04 Mar 2011 Posts: 11
|
Posted: Fri Mar 04, 2011 6:16 pm Post subject: |
|
|
Code: | {foreach name=Attribute from=$Artikel->Attribute item=Attribut}
<p><b>{$Attribut->cName}:</b> {$Attribut->cWert}</p>
{/foreach}
|
zeigt folgendes an:
farbe: blau |
|
Back to top |
|
jav664 Smarty Rookie
Joined: 04 Mar 2011 Posts: 11
|
Posted: Sat Mar 05, 2011 6:44 pm Post subject: |
|
|
Code: |
->Attribute = Array (1)
0 => stdClass Object (3)
->nSort = "1"
->cName = "farbe"
->cWert = "0"
|
vielleicht trägt das zur lösung des problems bei...
attribute ist ein array und da ist als element ein object drin, oder?
Last edited by jav664 on Sat Mar 05, 2011 6:53 pm; edited 1 time in total |
|
Back to top |
|
jav664 Smarty Rookie
Joined: 04 Mar 2011 Posts: 11
|
Posted: Sat Mar 05, 2011 6:52 pm Post subject: |
|
|
Code: | {$Artikel->Attribute[0]->cName} |
so gehts. |
|
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
|