Format addresses with address templates ​

An Address Template controls how ERPNext formats an address on documents, print formats, and emails. ERPNext picks the template from the address's Country. If no template exists for that country, it uses the template marked Is Default.

Prerequisites ​

  • System Manager role.
  • Basic HTML and Jinja knowledge.
  • A sample address with all fields filled, to test the result.

Create or edit a template ​

  1. Open the Address Template list. Open the template for the country, or select Add Address Template and select the Country.
  2. Copy the current template text, so that you can restore it.
  3. Enter the template in Template.
  4. Select Is Default only on the one template that is the fallback for all other countries.
  5. Save.
  6. Open an address of that country, and print a Quotation or Sales Invoice that uses it. Check line breaks, labels, and missing values.

WARNING

A syntax error affects every document that shows an address of that country. Test before you leave the change in place.

Write the template ​

Use the Address fieldnames in Jinja. Wrap optional fields in a condition, so that empty fields do not leave blank lines or stray commas:

jinja
{{ address_line1 }}<br>
{% if address_line2 %}{{ address_line2 }}<br>{% endif %}
{{ city }}{% if state %}, {{ state }}{% endif %} {{ pincode }}<br>
{{ country }}
FieldnameValue
address_line1First address line
address_line2Second address line
cityCity or town
countyCounty
stateState or province
pincodePostal code
countryCountry
phone, fax, email_idContact details on the address

Custom fields on Address are available by their fieldname. Fieldnames are case-sensitive. Use the fieldname, not the label.

Troubleshooting ​

ProblemCause and fix
The wrong format appearsThe address has the wrong Country, or no template exists for that country.
Blank lines or stray commasWrap the whole optional line in an if block.
A field never appearsThe fieldname is wrong, or the address has no value in that field.
The template saves, but the print breaksCheck that every HTML tag and Jinja block is closed.