2

I have a search module that grabs locations based on coordinates and estimates distances. I've decided to extend then channel class so I can take advantage of the entries method to display search results. In my method, I use an sql query to find the entry_ids and estimated distance. I then have the following:

public function search_results() {
    ...
    $entry_ids = '4|24|265|23';
    $distances = array(
        1.023536,
        1.254824,
        3.000325,
        4.923142
    );

    ee()->TMPL->tagparams['entry_id'] = $search_ids;
    return parent::entries();
}

This works great with the following code in my template, with one problem:

{exp:module:results}
    <li>
        <span>{distance}</span>
        <h4><a href="/location/{url_title}">{title}</a></h4>
        <div>{my_custom_field}</div>
    </li>
{/exp:module:results}

The "distance" is not a channel field, but that calculated value. Any suggestions on how I can inject that into the parsing per row?

3

You could create an extension which uses the channel_entries_query_result hook to add your variable to each entry row. That will get parsed along with the native vars. To pass data from your module/plugin file to the extension, you'd need to use the Session cache.

You might be interested to know that Low Search offers a straight forward API for custom filters, which basically extends the channel:entries tag, too. With it, in the same file, you can add your filter rules (which you have in your module/plugin file) and manipulate the output of the results (which you can do with an extension).

|improve this answer|||||
  • Thank you! That was the route I was planning on looking at today. You saved me from having to find the right hook and then realize the session cache piece. – koivi Dec 19 '14 at 16:57

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.