1

I'm using the address module with Drupal 8.x. I want a comma in the each line of the below address. Currently addresses display like:

John Peter
1181 Broadway
New York
SW1A 1AA
United Kingdom

I want it to display like:
John Peter,
1181 Broadway,
New York,
SW1A 1AA,
United Kingdom.

1 Answer 1

0

It appears you would need to write a custom address-plain.html.twig file and add it to the templates folder either in a module or in your theme.

Code:

<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>
2
  • FWIW you consider marking up the address using one of the techniques here: iandevlin.com/blog/2012/01/html/…
    – bleen
    May 10, 2018 at 19:27
  • That's really interesting, thanks for the link. I just used the template file that the module ships with and added the formatting changes @Kiran requested, since that seems to me to be the simplest solution. May 10, 2018 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.