Reputation: 931
I store my object data in a DB as ids. Say I have the following field stored in db as string:
2,3
and the following array stored some where in other place:
1 => low,
2 => medium,
3 => high
So when I retrieve this field in my twig template
{{ myobject.field }}
I get only 2,3, but I need something like
2 - medium, 3 - high
So I need to edit the data got in {{ myobject.field }} and add more info to it. What is the propoer way to do it with the help of Symfony? Is there something better than to manually reset object fields in foreach loop and overwrite the data stored there?
Thank you.
Upvotes: 1
Views: 67
Reputation: 4880
you need to understand a little on how twig calls properties of objects.
{{ myobject.field }}
is essentially the same as:
$myObject->getField()
so, in the twig way of doing things, itll return whatever the getter
returns. So if you want a specific format of the data returned, either adjust the current getField
method, or make a new one and call that instead.
Upvotes: 3