I have a list field for a custom content type that looks like this:
Field Machine name is: field_app_os
key|label
Win|Windows
Android|Android
I can access the key
in Twig template by using content.field_app_os
or Twig Field Value and the output of both is Android
:
Twig Field Value allows Drupal 8 themers to get partial data from field render arrays. It gives them more control over the output without drilling deep into the render array or using preprocess functions.
Filters:
- field_label : Returns the field label value.
- field_value : Returns the render array of the field value(s) without the field wrappers.
/* with use of Twig Field Value module */
{{ content.field_app_os|field_value }} {# outputs 'Android' #}
/* without use of Twig Field Value module */
{{ content.field_app_os }} {# outputs 'Android' #}
However, if I do a simple comparison, the output of both is False.
{% set app_os = content.field_app_os|field_value %}
{{ kint(app_os == 'Android') }} {# outputs 'bool FALSE' #}
Or When I use:
{% set app_os = content.field_app_os %}
{{ kint(app_os == 'Android') }} {# outputs 'bool FALSE' #}
What's wrong in my code?
node.field_app_os.value
then all things work correctly, But can you explain a little more about the cause of this issue, Please. – Mojtaba Reyhani Sep 28 '17 at 21:57