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

时间:2018-04-11 14:31:03

标签: templates twig drupal-8

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

我使用模块:

这是模块的模板"地址":

{#
/**
 * @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>

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

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

1 个答案:

答案 0 :(得分:0)

使用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')}}