Hi
Spent a couple of hours trying to figure out something I assumed would be really easy but I'm not getting it
I have over ridden my views-view-fields.html.twig file and that works fine
I render my fields using {{ fields.uid.content }} and that also works fine
What doesn't is if I try and run an if statement over it.
fields.uid.0 returns nothing
fields.uid.value also returns nothing
fields.uid causes an error
so how do I do something like
{% if fields.uid.content == 'John' %} ...
I need to do this in the fields twig template, not the field twig template as im adding some additional html in a separate place in the template based on the result
Many Thanks
Comments
so how do I do something like
What problems do you have with this expression?
Hi Wombatbuddy
It displays on the screen fine but if I try and do an if statement against it it doesn't work, I assume it is returning an array or similar and not just the raw value. So when I do {% if fields.uid.content == 'John' %} do x else do y, even when the content is John it still does y and doesn't recognise the content is John
You can explore it with kint(
You can explore it with kint() yourself.
But I gues that the reason may be that it output additional debug info.
You can try to remove it using 'striptags' filter, for instance, like this:
Thanks Again
That didn't work for me though unfortunately but did get me reading the right posts and based on what I read I went a different route as follows:
I just changed the output in my theme.module file and used the following (Added below to help others struggling with the same thing)
Hi,
Hi,
i run into same issues. I did copy your function into my_theme.theme, but i do get a syntax error. Do you have an idea whats wrong? Thanks a lot for helping!
/**
* Implements hook_preprocess_form_element().
*/
function my_theme_preprocess_views_view_field(&$variables) {
if ($variables['field']->field == 'field_typ') {
$variables['output'] = $variables['field']->getValue($variables['row']);
}