-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a way to display dropdown values with twig #3759
Comments
Hi @Alex360hd , You could create your own plugin for Twig dropdown support, like this one from @LukeTowers -> https://github.com/LukeTowers/oc-twigpcre-plugin. And add to the market, so that everyone could use it or help you anyhow. Or provide a PR to support this feature. |
@Alex360hd that's not really the responsibility of the frontend to know what you have labelled that key as in the backend. I'd agree with @w20k, implement it yourself as a separate plugin. |
Hello, It sound strange to me that a formWidget provided by core (dropdown) could not be displayed in frontend with ease and without external plugins, so I would prefer a PR solution directly to the core in order to support that. But if you still think it's not the job of the core, there is the excellent Twig extension plugin that I install on every project. Could be a nice addition to that plugin cause I don't want to create a plugin just to add a twig filter (Traumatized about Drupal and dozens of needed module in order to make it just usable). Thank you for the answer. Alex Edit : for people that want to follow this, I created an issue on the twigextensions plugin. It's the best place to add the feature for me. |
@Alex360hd it's not the job of the formwidget to display anything on the frontend, it's simply a tool of convenience for the backend users. Adding something in the core to do that would (in my opinion) be far too opinionated about how these things are used and setup. Remember, there are a lot of different ways that the options for a dropdown can be defined which means a lot of different places that the proposed solution would have to look for the desired strings that the option keys represented. You could do a simplistic version of what you want with the following: {{ mymodel.getMyDropdownOptions()[mymodel.mydropdown] }} |
Expected behavior
When I create some dropdown in the backend, I want to be able to easily display the key and / or the value of that dropdown in my templates, without writing PHP as it should be an easy and common task.
Actual behavior
Actually, you can only display the key by using {{ model.my_dropdown }}, there is no way (directly with twig) to display the dropdown value (which is a very basic task normally). I suggest to add a twig filter in order to deal with dropdown the way we want. For example :
{{ model.my_dropdown|key }} or {{ model.my_dropdown|value }}
Reproduce steps
October build
All
The text was updated successfully, but these errors were encountered: