render field in Views field template

Created on 7 June 2024, 21 days ago

I have a View of Article nodes and I want to theme one of the Article's image fields in my View, for example I want to say "print the url for this image" - can Twig Tweak help with this?

My template file name is working ok =

views-view-field--myarticlesview--page_1--field-my-image-field-here.html.twig

Original core template ( /web/core/modules/views/templates/views-view-field.html.twig ) =

{#
/**
 * @file
 * Default theme implementation for a single field in a view.
 *
 * Available variables:
 * - view: The view that the field belongs to.
 * - field: The field handler that can process the input.
 * - row: The raw result of the database query that generated this field.
 * - output: The processed output that will normally be used.
 *
 * When fetching output from the row this construct should be used:
 * data = row[field.field_alias]
 *
 * The above will guarantee that you'll always get the correct data, regardless
 * of any changes in the aliasing that might happen if the view is modified.
 *
 * @see template_preprocess_views_view_field()
 *
 * @ingroup themeable
 */
#}
{{ output -}}
πŸ’¬ Support request
Status

Active

Version

3.3

Component

Miscellaneous

Created by

πŸ‡¬πŸ‡§United Kingdom Juc1

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Juc1
  • πŸ‡·πŸ‡ΊRussia Chi

    If the template has a node variable then you can print any fields of it using Twig Tweak module.

  • πŸ‡¬πŸ‡§United Kingdom Juc1

    Ok but looking at the core Views template I posted above there is no node variable in "Available Variables" , so does that mean that Twig Tweak does not apply?

Production build 0.69.0 2024