Objekte und Arrays: Alle gegen Smarty

Shopware pflügt manchmal mit einer komischen Mischung aus Objekten und Arrays durch das Template, beispielweise auf den Herstellerseiten:

Shopware\Bundle\StoreFrontBundle\Struct\Product\Manufacturer Object
(
    [id:protected] => 1
    [name:protected] => Anton Schneider
    [description:protected] => 
    [metaTitle:protected] => 
    [metaDescription:protected] => 
    [metaKeywords:protected] => 
    [link:protected] => https://dev.wibros.eu/anton-schneider/
    [coverFile:protected] => https://cdn.cuckoopalace.com/media/vector/4c/76/c3/schneider.svg
    [attributes:protected] => Array
        (
            [core] => Shopware\Bundle\StoreFrontBundle\Struct\Attribute Object
                (
                    [storage:protected] => Array
                        (
                            [id] => 1
                            [supplierID] => 1
                            [wan] => AS
                            [wib_class] => schneider
                        )
 
                )
 
        )
 
)

Leider unterstützt Smarty die in php mittlerweile gültige Syntax get()['arraykey'] nicht.

{$manufacturer.getAttributes()['core']->get("wib_class")}

führt also zu einem Parse Error. Um jetzt doch an wib_class zu kommen muss man einen komischen Spagat machen:

{assign var="attr" value=$manufacturer->getAttributes()}
{assign var="class" value=$attr.core->get("wib_class")}

Bleibt die Frage: Warum?

Ich bin Web Developer und arbeite als Lead Developer bei WIBROS. Ich liebe das Internet, Baseball, Softball, Bier und die Farbe orange. Ich hab früher mal zu viel Kaffee getrunken.

Comment (1) Write a comment

  1. I find it strange how complex things can get when working with Smarty compared to just using plain PHP. Why not make Smarty more compatible with modern PHP syntax?

    Reply

Leave a Reply

Required fields are marked *.