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!

edit: variables enter image description here

using attribute , can access property of object in dynamic way. have use upper filter match need.

{{ attribute(record, 'estate_type_'~ activelocale|upper)|raw }} 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -