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

smarty-first steps: statt foreach auf eine variable gezielt

 
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
jav664
Smarty Rookie


Joined: 04 Mar 2011
Posts: 11

PostPosted: Fri Mar 04, 2011 5:32 pm    Post subject: smarty-first steps: statt foreach auf eine variable gezielt Reply with quote

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
View user's profile Send private message
U.Tews
Administrator


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

PostPosted: Fri Mar 04, 2011 6:00 pm    Post subject: Reply with quote

$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
View user's profile Send private message
jav664
Smarty Rookie


Joined: 04 Mar 2011
Posts: 11

PostPosted: Fri Mar 04, 2011 6:12 pm    Post subject: Reply with quote

exakt.

allerdings hat das array nur einen eintrag...bis jetzt.
Back to top
View user's profile Send private message
jav664
Smarty Rookie


Joined: 04 Mar 2011
Posts: 11

PostPosted: Fri Mar 04, 2011 6:16 pm    Post subject: Reply with quote

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
View user's profile Send private message
jav664
Smarty Rookie


Joined: 04 Mar 2011
Posts: 11

PostPosted: Sat Mar 05, 2011 6:44 pm    Post subject: Reply with quote

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
View user's profile Send private message
jav664
Smarty Rookie


Joined: 04 Mar 2011
Posts: 11

PostPosted: Sat Mar 05, 2011 6:52 pm    Post subject: Reply with quote

Code:
{$Artikel->Attribute[0]->cName}


so gehts.
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