How to get the values by twig_tweak?

Created on 6 March 2025, about 1 month ago

Hello,

I created a custom field (field_data) and added three values (num, year, code).

I want to obtain one of the values, such as year, through twig_tweak. How should I proceed?

{{ drupal_field('field_data', 'node', nid) }}
It gets the value of the entire field.

I want to get the year value, I'm trying to do this, however, there was no result:
{{ drupal_field('field_data', 'node', nid, {values:"year"}) }}

[node:field_data:year]
Of course, I can use a token to obtain it, but it can only obtain the field values of the current node.

I need to obtain it through the NID of the node, how to do?

Thank you

πŸ’¬ Support request
Status

Active

Version

3.1

Component

Miscellaneous

Created by

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

Comments & Activities

  • Issue created by @msn5158
  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    I've never used twig_tweak but from the cheat sheet listed on the module page, it looks to be pretty specifically coded for the common fields in core and doesn't look to support custom fields with properties unknown to its own api. You might ask in their channel but I don't really know how I could help you for this module. Generally speaking, theres a ton of formatters that come with this module with some advanced display settings like being able to modify field wrappers and add classes so not really sure how much value twig_tweak would provide beyond that.

Production build 0.71.5 2024