如何在Drupal/Twig视图中获取分类学术语ID

发布于 2025-01-26 10:51:28 字数 614 浏览 4 评论 0原文

希望你一切都好。 我从Drupal开始。 我被要求更改

  • 字段类,当它具有以前定义为默认值的一定值时。

    如果我插入这是视图< p> {{content.field_solution_by_default}}}</p>

    它将正确打印字段的文本,但要更改

  • 类,我需要“ datavalue” ”。

    任何人都知道这样做的任何方法,我已经尝试了以下内容:

      {{attribute(content.field_solution_by_default,datavalue)}}}
    {{drupal_field(content,field_solution_by_default,tid)}}}
    {{content.field_solution_by_default.0 ['#saxonomy_term'] ['tid']}}}
    {{content.field_solution_by_default ['#galsonomy_term'] [0] .value}}}
     

    PHP 7.3 Drupal 9.3

  • hope you doing well.
    I'm starting with drupal.
    and i was asked to change a

  • field class when it has a certain value previously defined as default.

    if i insert this is the view <p>{{ content.field_solution_by_default}}</p>

    it will print the Text of the field correctly, but to change the

  • class i need the "datavalue".

    any one knows any way of doing this, i already tryed the followings:

    {{ attribute(content.field_solution_by_default, datavalue) }}
    {{ drupal_field(content, field_solution_by_default, tid) }}
    {{ content.field_solution_by_default.0['#taxonomy_term']['tid'] }}
    {{ content.field_solution_by_default['#taxonomy_term'][0].value }}
    

    php 7.3
    drupal 9.3

  • 如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

    扫码二维码加入Web技术交流群

    发布评论

    需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

    评论(1

    初雪 2025-02-02 10:51:28

    好的。假设您使用分类法创建了一个视图,并定义了以标题,正文和分类法显示的字段:在这种情况下,我称其为type_pf(经常询问问题类型):

    {% for row in content['#view'].result %}
      {{ content['#view'].field['title'].value(row) }}
      {{ content['#view'].field['body'].value(row) | raw}}
      {{ content['#view'].field['field_type_pf'].value(row) }}
    {% endfor %}
    

    那样,该字段,显示在视图中。

    也就是说,我不知道为什么它向我显示ID,而不是分类法的名称:

    {{ content['#view'].field['field_tipo_pf'].value(row) }}
    

    仍然有帮助。

    Good. Assuming that you created a view with the taxonomies and defined the fields to show as title, body and the taxonomy: In this case, I call it type_pf (frequently asked question type):

    {% for row in content['#view'].result %}
      {{ content['#view'].field['title'].value(row) }}
      {{ content['#view'].field['body'].value(row) | raw}}
      {{ content['#view'].field['field_type_pf'].value(row) }}
    {% endfor %}
    

    That way, the fields are displayed in the views.

    That said, I don't know why it shows me the id instead the name of the taxonomy in:

    {{ content['#view'].field['field_tipo_pf'].value(row) }}
    

    Still, this should help.

    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文