[gelöst] Array auslesen

Diskussionen zur Smarty-Template-Engine
Post Reply
nockenfell
Power Poster
Power Poster
Posts: 751
Joined: Fri Sep 12, 2008 2:34 pm
Location: Schweiz / Switzerland

[gelöst] Array auslesen

Post by nockenfell »

Ich bin im Moment daran mit Products ein Übersichtstemplate zu erstellen. Folgendes Array ergibt sich aus $entry:

Code: Select all

stdClass Object
(
    [id] => 2
    [product_name] => Design Tiger Babe
    [details] => 
    [detail_url] => /index.php?mact=Products,cntnt01,details,0&cntnt01category=Ladys%20-%20Hoodies&cntnt01productid=2&cntnt01returnid=43
    [file_location] => /uploads/Products/product_2
    [fields] => Array
        (
            [artikelnr] => stdClass Object
                (
                    [id] => 8
                    [name] => artikelnr
                    [prompt] => Artikel-Nr
                    [type] => textbox
                    [options] => Array
                        (
                            [] => 
                        )

                    [max_length] => 255
                    [fielddef_id] => 8
                    [value] => HODW 01001
                )

            [picture1] => stdClass Object
                (
                    [id] => 2
                    [name] => picture1
                    [prompt] => Produktbild 1
                    [type] => image
                    [options] => Array
                        (
                            [] => 
                        )

                    [max_length] => 255
                    [fielddef_id] => 2
                    [value] => 1.JPG
                    [thumbnail] => thumb_1.JPG
                    [preview] => preview_1.JPG
                )
)
Nun möchte ich die den Value der artikelnr und das thumnail von picture1 auslesen. Ziel ist es am Schluss

Produktname
Artikel-Nr
Bild

anzuzeigen. Eine foreach Schlaufe kann ich hier nicht machen denke ich, da ich ja gezielt einen Wert ausgeben will. Wir komme ich hier zu den Daten. Ich steh auf dem Schlauch.
Last edited by nockenfell on Sat Jan 16, 2010 5:36 pm, edited 1 time in total.
[this message is written with 100% recycled bits]
nhaack

Re: Array auslesen

Post by nhaack »

{$entry->fields['artikelnr']->id}

und

{$entry->fields['picture1']->thumbnail}

...

Oder nicht?

Beste Grüße
Nils
nockenfell
Power Poster
Power Poster
Posts: 751
Joined: Fri Sep 12, 2008 2:34 pm
Location: Schweiz / Switzerland

Re: Array auslesen

Post by nockenfell »

nhaack wrote: {$entry->fields['artikelnr']->id}
{$entry->fields['picture1']->thumbnail}
eben nicht :

string(184) "Smarty error: [in module_db_tpl:Products;summary_artikeluebersicht line 22]: syntax error: unrecognized tag: $entry->fields['picture1']->thumbnail (Smarty_Compiler.class.php, line 446)" string(148) "Smarty error: [in module_db_tpl:Products;summary_artikeluebersicht line 22]: syntax error: unrecognized tag '' (Smarty_Compiler.class.php, line 590)"
[this message is written with 100% recycled bits]
NaN

Re: Array auslesen

Post by NaN »

Und was ist damit:

Code: Select all


{$entry->fields.artikelnr->id}

Das mit der eckigen Klammer geht soweit ich weiß nur mit dem numerischen Index eines Arrays:

Code: Select all


{$entry->fields[0]->id}

Für den assoziativen Index ist der Dot-Syntax:
{$foo.bar}    <-- display the "bar" key value of an array, similar to PHP $foo['bar']
http://www.smarty.net/manual/en/languag ... iables.php
nhaack

Re: Array auslesen

Post by nhaack »

Wieder was dazugelernt. Super. Danke!
nockenfell
Power Poster
Power Poster
Posts: 751
Joined: Fri Sep 12, 2008 2:34 pm
Location: Schweiz / Switzerland

Erledigt Re: Array auslesen

Post by nockenfell »

Super das war's. In der Dokumentation habe ich das auch gelesen. Jedoch schlussendlich die Punkte am falschen Ort gesetzt.

Danke!
[this message is written with 100% recycled bits]
Post Reply

Return to “Smarty-Tipps und -Tricks”