objectivehtml / Google-Maps-for-Craft

The complete geolocation toolkit for Craft CMS.
Other
94 stars 20 forks source link

Pull extract from marker.address #38

Closed niallthompson closed 8 years ago

niallthompson commented 9 years ago

Using {{ marker.address }} in my template is there a way to just get the city or locality?

For example: London or Los Angeles.

This is my current markup:

{% for marker in entry.location.getMarkers() %}{{ marker.address }}{% endfor %}

Jammooka commented 9 years ago

You can use marker.addressComponents instead.

Output {{ dump(marker.addressComponents) }} and you'll see the full array.

In your particular case, you'd probably have to do something like:

{% for part in marker.addressComponents %}
    {% if part.types[0] == 'postal_town' %}{{ part.long_name }}{% endif %}
{% endfor %}
objectivehtml commented 8 years ago

Just for reference, you can also use {{ marker.formattedAddress }}.