2

I have "locations" section where each entry is a location, with a Smart Map field for the address.

I have another section "pages", where I have a matrix field which contains an entry relationship field, where I can select entries (locations) from the first channel.

I'm trying to output a map of all locations selected in my matrix field, but I'm getting an error: Property "Craft\SmartMap_AddressModel.title" is not defined.

I'm using the code below to get the address fields from the individual entries, and put them into an array. I think maybe I'm not understanding what exactly needs to be in the locations array:

{% set locations = [] %}

{#  loop though all relationship fields for this entry #}
{% for block in entry.pageBuilder.type('listingGroup') %}

    {#  loop through related entries #}
    {% for member in block.listing %}

        {# get individual entry address #}
        {% set address = member.address %}

        {# add entry address to locations array #}
        {% set locations = locations|merge([address])%}

    {% endfor %}
{% endfor %}

{{ craft.smartMap.map(locations, options) }}
2

At a glance, your code looks perfect... but I think there's a subtle error. The locations parameter can be an array of elements, but you are building an array of Address fields (which is not valid).

https://www.doublesecretagency.com/plugins/smart-map/docs/render-a-map-in-twig

locations

You can simplify the middle part of your code to this:

        {# add entry to locations array #}
        {% set locations = locations|merge([member])%}

That way, locations will end up being an array of elements.

  • That did it. Makes sense. I think in my head, doing it that way didn't seem specific enough. – artmem Aug 30 '17 at 19:08
  • Is it possible to get reverse relationship data back out of my locations array? Each matrix block has a field for venueType, in addition to my relationship field. I'd like to be able to get the venueType data for each location to create custom icons. {% set venues = craft.entries.section('members','events').relatedTo({ targetElement: entry, field: 'myMatrix.matrixRelationshipField' }) %} doesn't work. – artmem Sep 8 '17 at 16:56
  • Figured it out: {% set venue = entry.featuredMembers.myMatrix.relatedTo(location).first() %} {{ venue.venueType }} – artmem Sep 8 '17 at 17:13
  • @artmem That sounds like a completely unrelated question, and should probably be asked as a new thread (for future reference). – Lindsey D Sep 8 '17 at 17:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.