Ok, the title is really bad, but I’ll try to explain… 😊
I’m making a custom addon for a project I’m working on, which basicly is going to return channel entries based on a special sort criteria which uses data from several custom fields, runs them true a formula and returns the entries that satisfies the criteria. In an order based on the relevancy. I’ve made the code that picks up the parameters from the module tag, queries the database accordingly, and gets a sorted array with entry_ids and their relevancy. So far, so good…
The module should behave like the exp:channel:entries tag, so I stuck my head into LOWs Reorder addon, which do exactly that, to see if I could understand how to get the appropriate channel entries (yes, I’m a total noob). Turns out, I learnt alot, and what I came out with was that I can do something like this to get the entries I want, in the right order (simplified example):
// set the fixed order template parameter to the entry ids I found
$this->EE->TMPL->tagparams['fixed_order'] = $search_entry_ids;
if ( ! class_exists('channel')) {
require_once PATH_MOD.'channel/mod.channel'.EXT;
}
$channel = new Channel();
return $channel->entries();Great, so inside my {exp:custom_addon:entries} tag, I now can output {entry_id}, {title}, and all the other tag variables. But, and here’s my question; I need to add another variable to each entry, how do I do that? Inside my module I have the id’s my search returned and a relevance factor. In my template I need to be able to get this by going {relevancy} inside my tag loop.
Maybe I’m going about this all wrong, but… Anyone?
Ah, I see. And that would probably mean that I would have to do the search all over again? Or can I somehow pass the data I have in the module to the extension?
Do you hav some pointers to how not to piggy back the Channel module? Would that mean that I’d have to parse custom fields and stuff all with custom code?
You can store you module data temporary in the $this->EE->session->cache array. And access it from your extension. http://ellislab.com/expressionengine/user-guide/development/usage/session.html#cache-array
As for not piggy backing the channel module, you would need to parse all channel data yourself then. Since you are doing a custom module, maybe you already know what fields you need?
Ah, the session cache, of course.
Yes, I could actually get away with only returning entry_id and relevancy on this project, but I thought it would be much more useful for future projects if I went all in and made it return complete channel entries. Also, I’m trying to learn how to develop ee-addons, so it seemed like a nice challenge. 😉
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.