We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Adding variable to channel entries return data in custom addon

Development and Programming

aelvan's avatar
aelvan
33 posts
13 years ago
aelvan's avatar aelvan

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?

       
Manuel Payano's avatar
Manuel Payano
144 posts
13 years ago
Manuel Payano's avatar Manuel Payano

Well since you are piggy backing the Channel Module and returning it’s result you have very few options. You would need an extension (http://ellislab.com/expressionengine/user-guide/development/extension_hooks/module/channel/index.html#channel-entries-tagdata-end)

       
aelvan's avatar
aelvan
33 posts
13 years ago
aelvan's avatar aelvan

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?

       
Manuel Payano's avatar
Manuel Payano
144 posts
13 years ago
Manuel Payano's avatar Manuel Payano

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?

       
aelvan's avatar
aelvan
33 posts
13 years ago
aelvan's avatar aelvan

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. 😉

       
aelvan's avatar
aelvan
33 posts
13 years ago
aelvan's avatar aelvan

Thanks a bunch man, creating an extension and hooking into channel_entries_query_result did the trick! 😊

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.