Hiding Country from an Address Field’s Output in Drupal 8

There are two field formatters available on an Address field in Drupal 8:

The Plain formatter uses a Twig template file but it would take some work to override with the proper markup. The Default formatter doesn’t use a Twig template file so you cannot simply override via Twig.

If your goal is to simply hide the¬†country value from the output you can use hook_preprocess_field to alter the country value. As it turns out, unsetting the country field doesn’t help, but setting the value to an empty string does work.

Here’s an example (in a module; you can put in your .theme file if you’d prefer the setting to be at the theme level).

 

Tagged with: , ,
Posted in Development

Leave a Reply

Your email address will not be published. Required fields are marked *

*