In Document or Message Templates, when you want to display an address you need to include all of the address fields and would use merge fields to achieve this:
In this example the address of a referee is being used:

Usually at least one of the address fields will have nothing in them (address line 3 for example), but by default if a field is blank then the Document or Message template will use a blank line, this is an eyesore but it can be suppressed.
Each line of the address (or any merge field) can be conditioned so that it only displays if there is data in it.
e.g. 'If there is an address line 3 then display it, if there isn't one then skip it without adding an extra line break in'
In the template, add some conditioning around the merge field, in this example I will use Address line 3:
<%if reference.referee_data.field_address3 %> <<reference.referee_data.field_address3>><% endif %>
Here is a breakdown of what each section means:
< if there is an address line 3> <<then display address line 3>> <end the IF statement>
Now, to stop the blank line appearing, click the Source button at the top left, your If statement for address line 3 will look like this:
<%if target.field_address3 %> <<target.field_address3>> <% endif %><br />
The <br /> means 'line break'. You need to move the line break before the 'End If' part (the 3rd section of the IF statement), so place it as shown below:
<%if target.field_address3 %> <<target.field_address3>><br /><% endif %>
An example of a full address where each line is conditioned (in the Source):
<%if target.field_address1 %> <<target.field_address1>> <% endif %>
<%if target.field_address2 %> <<target.field_address2>> <% endif %>
<%if target.field_address3 %> <<target.field_address3>> <% endif %>
<%if target.field_city %> <<target.field_city>> <% endif %>
<%if target.field_county %> <<target.field_county>> <% endif %>
<%if target.field_postal_code %> <<target.field_postal_code>> <% endif %>
Notes:
Watch out for rogue spaces! these will disrupt the syntax.
Always make backups before you change live templates.
Comments
0 comments
Please sign in to leave a comment.