Twig, blocks, and localizedfields


In my class, I have a block that contains a localizedfield. I can’t seem to figure out how to make twig reference the fields within the localizedfield as I iterate the block:


I got further but is there not some kind of twig/pimcore idiom to by-pass traversing through the localizedfield as so:


Never use the direct access to variables. From Pimcore v5.5.0 and higher the variables of the DataObjects are now protected so you can’t access them directly.
Always use the Getters like in your case part.getPartName


@davidhoeck in twig that doesn’t matter, twig always checks for a getter first and then for a direct property.


I know, but I had the same error also and my solution was to use directly the getter … maybe it solves his problem too


The getter isn’t working, which is why I went elsewhere. How do you declare the language within twig?


but in twig:

{{ dump(step.localizedfields.getData.getItems) }}
it returns an assoc. array; however, when you attempt to access it via the key, it only sees “en_US” and not “zh”, which throws an key error.

I’m missing something…


The twig dump:

{{ dump(step.localizedfields.getData.getItems.en_US) }}
doesn’t throw an error.
{{ dump(step.localizedfields.getData.getItems.zh) }}
does throw an error.


The locale within Twig is defined via the global Symfony ‘locale’ parameter


Makes sense for the default, but then how do you show multiple languages on a single page?


{{ dump(step.localizedfields.getData.getItems|keys) }}
but I don’t seem able to access the values via the key “zh”
{{ dump(step.localizedfields.getData.getItems.zh) }}
throws a key error.


This works in the console, however:


I think I finally figured it out. One of the blocks didn’t have Chinese registered so it worked on all those with it and throws the error if not. Doh.