All custom fields are empty in Twig template

Created on 21 August 2023, over 1 year ago
Updated 25 April 2024, 7 months ago

Problem/Motivation

Most of the custom fields when accessed from civicrm-entity--civicrm-contact.html.twig are empty.

E.g.

  "custom_123" => array:2 [▼
    "#cache" => array:3 [▶]
    "#weight" => 0
  ]
  "custom_1234" => array:2 [▼
    "#cache" => array:3 [▶]
    "#weight" => 0
  ]

Why is that?

Steps to reproduce

{{ dump(content) }}
{{ devel_dump(content) }}
🐛 Bug report
Status

Closed: works as designed

Version

3.5

Component

Code

Created by

🇬🇧United Kingdom kenorb

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

Comments & Activities

  • Issue created by @kenorb
  • 🇬🇧United Kingdom kenorb

    Did access them using different approach, by extending some classes.
    Then loading them via {% set civicrm_entity = content.contact_type['#object'] %}
    Some code customization which I did: https://www.drupal.org/project/civicrm_entity/issues/3382166#comment-152... Website URL not exposed Active

  • 🇺🇸United States markusa

    Thanks!! We'll be looking into why these fields are not automatically available in the template as variables

  • 🇵🇭Philippines dsdeiz

    Yeah, it's supposed to be there. This is what I see on my end:

    "custom_1" => array:18 [▼
        "#theme" => "field"
        "#title" => "Test"
        "#label_display" => "hidden"
        "#view_mode" => "full"
        "#language" => "und"
        "#field_name" => "custom_1"
        "#field_type" => "string"
        "#field_translatable" => false
        "#entity_type" => "civicrm_contact"
        "#bundle" => "civicrm_contact"
        "#object" => Drupal\civicrm_entity\Entity\CivicrmEntity {#2727 ▶}
        "#items" => Drupal\Core\Field\FieldItemList {#2677 ▶}
        "#formatter" => "string"
        "#is_multiple" => false
        "#third_party_settings" => []
        0 => array:3 [▼
          "#type" => "inline_template"
          "#template" => "{{ value|nl2br }}"
          "#context" => array:1 [▼
            "value" => "1234"
          ]
        ]
        "#cache" => array:3 [▶]
        "#weight" => 0
      ]

    Maybe check if the the custom fields are enabled on the "Manage display"?

  • Status changed to Closed: works as designed 7 months ago
  • 🇺🇸United States markusa

    Did a custom template recently and the custom fields were available and showed values when the template was rendered.

Production build 0.71.5 2024