gpt4 book ai didi

templates - 如何显示城市和邮政编码?

转载 作者:行者123 更新时间:2023-12-03 19:35:27 25 4
gpt4 key购买 nike

我有一个使用 Drupal 8 的站点,我想自定义我的页面模板。

我使用模块:

  • 《简介》https://www.drupal.org/project/issues/profile
  • “地址”https://www.drupal.org/project/address

  • 这是模块“地址”的模板:
    {#
    /**
    * @file
    * Default template for the 'plain' address formatter.
    *
    * Available variables:
    * - given_name: Given name.
    * - additional_name: Additional name.
    * - family_name: Family name.
    * - organization: Organization.
    * - address_line1: First address line.
    * - address_line2: Second address line.
    * - postal_code: Postal code.
    * - sorting_code: Sorting code.
    * - dependent_locality: The dependent locality.
    * - dependent_locality.code: Dependent locality code.
    * - dependent_locality.name: Dependent locality name.
    * - locality: The locality subdivision.
    * - locality.code: Locality code.
    * - locality.name: Locality name.
    * - administrative_area: The administrative area subdivision.
    * - administrative_area.code: Administrative area code.
    * - administrative_area.name: Administrative area name.
    * - country: The country.
    * - country.code: Country code.
    * - country.name: Country name.
    *
    * if a subdivision (dependent_locality, locality, administrative_area) was
    * entered, the array will always have a code. If it's a predefined subdivision,
    * it will also have a name. The code is always prefered.
    *
    * @ingroup themeable
    */
    #}
    <p class="address" translate="no">
    {% if given_name or family_name %}
    {{ given_name }} {{ family_name }} <br>
    {% endif %}
    {% if organization %}
    {{ organization }} <br>
    {% endif %}
    {% if address_line1 %}
    {{ address_line1 }} <br>
    {% endif %}
    {% if address_line2 %}
    {{ address_line2 }} <br>
    {% endif %}
    {% if dependent_locality.code %}
    {{ dependent_locality.code }} <br>
    {% endif %}
    {% if locality.code or postal_code or administrative_area.code %}
    {{ locality.code }} {{ postal_code }} {{ administrative_area.code }} <br>
    {% endif %}
    {{ country.name }}
    </p>

    这是我自定义个人资料页面的模板:
    {#
    /**
    * @file
    *
    * Default theme implementation for profiles.
    *
    * Available variables:
    * - content: Items for the content of the profile.
    * Use 'content' to print them all, or print a subset such as
    * 'content.title'. Use the following code to exclude the
    * printing of a given child element:
    * @code
    * {{ content|without('title') }}
    * @endcode
    * - attributes: HTML attributes for the wrapper.
    * - profile: The profile object.
    * - url: The profile URL, if available.
    *
    * @ingroup themeable
    */
    #}
    <div{{ attributes.addClass('profile--personnel--teaser') }}>

    <div class="views-row">

    <div class="views-teaser-profil-address">
    {{ content.field_personnel_adresse }}
    </div>

    </div>

    </div>

    当前显示完整地址。如何只显示城市和邮政编码?

    我只想要没有标签的文本。

    最佳答案

    使用kint()这样您就可以深入研究所有这些值

    {{ kint(content.field_personnel_adresse.0) }}
    <div>
    {{ content.field_personnel_adresse.0.locality['#value'] }}
    {{ content.field_personnel_adresse.0.postal_code['#value'] }}
    </div>
    {{ content|without('field_personnel_adresse')}}

    关于templates - 如何显示城市和邮政编码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49777810/

    25 4 0