Twig translate dynamic value/string from database -
explanation:
pull these values local database , try display them on front-end. issue is, have 2 languages need cater to.
example:
{% if activelocale == "si" %} {{ record.estate_type_si|raw }} {% elseif activelocale == "en" %} {{ record.estate_type_en|raw }} {% endif %}
this works, when have multiple items gets gruesome because have write down 2 times. depending on language value different column in database pulled.
i wondering if can similar this:
{{ record.estate_type_{{"si"|trans}}|raw }}
i gladly buy beer if can me out this. cheers!
using attribute , can access property of object in dynamic way. have use upper filter match need.
{{ attribute(record, 'estate_type_'~ activelocale|upper)|raw }}
Comments
Post a Comment