You are here

viewfield-item.html.twig in Viewfield 8.3

Default theme implementation to display a viewfield item.

Instead of overriding the theming for all fields, you can also just override theming for a subset of fields using Theme hook suggestions. For example, here are some theme hook suggestions that can be used for a field_foo field on an article node type:

  • viewfield-item--my-view--my-view-display.html.twig
  • viewfield-item--my-view-display.html.twig
  • viewfield-item--my-view.html.twig
  • viewfield-item--field-foo--my-view--my-view-display.html.twig
  • viewfield-item--field-foo--my-view-display.html.twig
  • viewfield-item--field-foo--my-view.html.twig
  • viewfield-item--field-foo--2.html.twig
  • viewfield-item--field-foo.html.twig
  • viewfield-item.html.twig

Available variables:

  • title: The title of this item if visible.
  • content: The content of this item.
  • attributes: array of HTML attributes populated by modules, intended to be added to the main container tag of this template.
  • title_attributes: Same as attributes, except applied to the main title tag that appears in the template.
  • title_prefix: Additional output populated by modules, intended to be displayed in front of the main title tag that appears in the template.
  • title_suffix: Additional output populated by modules, intended to be displayed after the main title tag that appears in the template.
  • delta: Ordinal specifying the item number in the field.
  • entity: The entity object.
  • view_mode: View mode; e.g., 'full', 'teaser', etc.

File

templates/viewfield-item.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Default theme implementation to display a viewfield item.
  5. *
  6. * Instead of overriding the theming for all fields, you can also just override
  7. * theming for a subset of fields using
  8. * @link themeable Theme hook suggestions. @endlink For example,
  9. * here are some theme hook suggestions that can be used for a field_foo field
  10. * on an article node type:
  11. * - viewfield-item--my-view--my-view-display.html.twig
  12. * - viewfield-item--my-view-display.html.twig
  13. * - viewfield-item--my-view.html.twig
  14. * - viewfield-item--field-foo--my-view--my-view-display.html.twig
  15. * - viewfield-item--field-foo--my-view-display.html.twig
  16. * - viewfield-item--field-foo--my-view.html.twig
  17. * - viewfield-item--field-foo--2.html.twig
  18. * - viewfield-item--field-foo.html.twig
  19. * - viewfield-item.html.twig
  20. *
  21. * Available variables:
  22. * - title: The title of this item if visible.
  23. * - content: The content of this item.
  24. * - attributes: array of HTML attributes populated by modules, intended to
  25. * be added to the main container tag of this template.
  26. * - title_attributes: Same as attributes, except applied to the main title
  27. * tag that appears in the template.
  28. * - title_prefix: Additional output populated by modules, intended to be
  29. * displayed in front of the main title tag that appears in the template.
  30. * - title_suffix: Additional output populated by modules, intended to be
  31. * displayed after the main title tag that appears in the template.
  32. * - delta: Ordinal specifying the item number in the field.
  33. * - entity: The entity object.
  34. * - view_mode: View mode; e.g., 'full', 'teaser', etc.
  35. *
  36. * @see template_preprocess_viewfield_item()
  37. *
  38. * @ingroup themeable
  39. */
  40. #}
  41. {%
  42. set classes = [
  43. 'field__item',
  44. 'field__item-label-' ~ label_display,
  45. ]
  46. %}
  47. {%
  48. set title_classes = [
  49. 'field__item__label',
  50. label_display == 'visually_hidden' ? 'visually-hidden',
  51. ]
  52. %}
  53. <div{{ attributes.addClass(classes) }}>
  54. {{ title_prefix }}
  55. {% if not label_hidden and label %}
  56. <div{{ title_attributes.addClass(title_classes) }}>{{ label }}</div>
  57. {% endif %}
  58. {{ title_suffix }}
  59. {% block content %}
  60. {{ content }}
  61. {% endblock %}
  62. </div>