0

So i am working on a Shopware shop, and i want to read a MediaEntity in Twig. To do so, i am creating a string with the node path (adding the product ID as a variable), which just works fine. To actually access the MediaEntity, i need to convert this string into a real node path. How do i do that? Or is there maybe another way to create this path? Here's my code:

{% block component_product_box %}
    {{ parent() }}       
    {% set coverIds = "context.extensions.#{product.coverId}.elements" %}
    {{ dump() }}

{% endblock %}
3

1 Answer 1

0

I tried it roughly and something like this should work:

{% set coverIds = _context['extensions'][product.coverId]['elements'] %}

This should solve your problem, I hope.

If you really need to work with a string and "dots" notation, this could be of help:

How to use Twig's attributed function to access nested object properties

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.