2

I'm trying to search through a set of results inside a Matrix field. Craft is giving me this error message: Craft\EntryModel and its behaviors do not have a method or closure named "avdelinger".

When I searched the information without the Matrix field it worked but now it's not. I'm using the smart map plugin to find the nearest office added in my Matrix field. Here's my code:

{% block content %}

<form action="">
    <input type="search" name="sted" placeholder="Search">
    <input type="submit" value="Go">
</form>

{% for block in entry.avdelinger %}
    <div>
        <h3>{{ block.navn }}</h3>
        {{ block.sted.street1 }}<br />
        {{ block.sted.city }}, {{ block.sted.zip }}
    </div>
    <div>
        Latitude: {{ block.sted.lat }}<br />
        Longitude: {{ block.sted.lng }}
    </div>
{% endfor %}


<!-- results -->
{% set target = craft.request.getParam('sted') %}
{% set params = {
    target: target,
    range: 1000,
    units: "kilometers"
} %}

{% set blocks = entry.avdelinger(params).order('distance').find() %}

<h2>Showing results for "{{ target }}"</h2>
{% for block in blocks %}
    <div>
        {{ block.sted.street1 }}<br />
        {{ block.sted.city }}, {{ block.sted.zip }}<br>
        <strong>{{ block.sted.distance | number_format(2) }} kilometers away</strong>
    </div>
{% else %}
    <h2>No results found</h2>
{% endfor %}

{% endblock %}

Thanks!

2

The syntax to set a custom field parameter on a Matrix Block element criteria model is like so:

{% set blocks = entry.myMatrixField.mySmartMapField(params) %}
| improve this answer | |

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.