Is it possible to use trans filter or path function dynamically?With variables as parameters? ex1:
{{ path('object_edit', { parameter_type : parameter_value }) }}
because: I don't know if "object" using id or slug for routing
ex2:
{{message|trans({ parameter_type : parameter_value }, 'TranslationDomain') }}
because: i don't know if it will be '%user%' or '%article%' or something else
Why this works fine:
{{ path('object_edit', { 'id' : parameter_value }) }}
but this doesn't:
{{ set parameter_type = 'id' }}
{{ path('object_edit', { parameter_type : parameter_value }) }}
{% set key = 'foobar' %}
{% set hash = { (key) : 'hello world' } %}
{% debug hash %}
prints:
array(1) { ["foobar"]=> string(11) "hello world" }
wrapping in parenthesis solves your problem.
Enclose the hash keys with parenthesis (not braces).
{{ path('object_edit', { (parameter_type) : parameter_value }) }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With