isEmpty and hasCoords

Smart Map has been replaced by Google Maps

Please install the Google Maps plugin instead. ➡️

As of February 2021, the Smart Map plugin has been completely rebuilt and replaced with the new Google Maps plugin for Craft CMS. For more details, see here...


The documentation below is for historical reference only.

To make Twig logic a little easier, the Address model includes two methods...

# .isEmpty

You can easily see if any parts of an address exist by using isEmpty:

{% if not entry.myAddressField.isEmpty %}
    {{ entry.myAddressField.format }}
{% endif %}

The isEmpty detection does not include coordinates... It only cares if any of the address fields have been completed.

# .hasCoords

To check if a valid coordinate set exists, you can use hasCoords:

{% if entry.myAddressField.hasCoords %}
    Latitude:  {{ entry.myAddressField.lat }}<br>
    Longitude: {{ entry.myAddressField.lng }}
{% endif %}

The hasCoords method ensures that both coordinates exist, and are numeric.