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

Custom module passing entry id to exp:channel:entries

Development and Programming

Studio Meta's avatar
Studio Meta
105 posts
15 years ago
Studio Meta's avatar Studio Meta

Hello,

Is there any way to “embed” an exp:channel:entries tag into a module tag ?

Here is a quick example of what I want to do :

{exp:mymodule:search_results}

{exp:channel:entries}
{title} : {custom_field}
{/exp:channel:entries}

{/exp:mymodule:search_results}

The aim is to keep all advantages of the channel module, while being able to fetch only the needed entries.

My first idea was to pass a list of entries ID to the module, but there may be a cleverest way to do that ?

I’ve looked at search module source code (which does something similar), but it create a new Channel class, and I’m not sure doing like this will keep all the channel module features (ie: pagination, switch variable, etc…).

Any help highly appreciated, thanks !

       
Studio Meta's avatar
Studio Meta
105 posts
15 years ago
Studio Meta's avatar Studio Meta

Finally I’ve found a solution to my problem, I post it here so maybe it could help somebody.

I’m curious, does someone at EllisLab can tell me if it’s a good way to work with channel entries please ?

Step 1 : Create a new class which extends Channel

<?php 
if ( ! defined('EXT')) { exit('Invalid file request'); }

if( ! class_exists( 'Channel' )) { require_once PATH_MOD.'channel/mod.channel.php'; }

class Mymodule_entries extends Channel {

    public $return_data;
    
    private $channel         = false;
    private $url_title      = false;
    private $status         = false;
    private $category_group = false;
    private $category       = false;
    private $group_id       = false;
    private $author_id      = false;

    public function __construct() 
    {
    
        $this->EE =& get_instance();
    
        parent::Channel();
        $this->_params();

    }
    
    

    /** ----------------------------------------
    /**  Setup default parameters
    /** ----------------------------------------*/    
    private function _params()
    {
        $this->channel            = $this->EE->TMPL->fetch_param('channel');
        $this->url_title        = $this->EE->TMPL->fetch_param('url_title');
        $this->status            = $this->EE->TMPL->fetch_param('status', 'open');
        $this->category_group    = $this->EE->TMPL->fetch_param('category_group');
        $this->category            = $this->EE->TMPL->fetch_param('category');
        $this->group_id            = $this->EE->TMPL->fetch_param('group_id');
        $this->author_id        = $this->EE->TMPL->fetch_param('author_id');
    }
    
    

    /** ----------------------------------------
    /**  Set up the tagparams with the IDs of search results entries before running the channel:entries method
    /** ----------------------------------------*/     
    public function entries($entry_array)
    {
        if(!is_array($entry_array))
            return FALSE;

        $entries = implode('|', $entry_array);
        $this->EE->TMPL->tagparams['entry_id'] = $entries;
       
        return parent::entries();
    }    
    
}
        

?>

Step 2 : in your exp:mymodule:function simply load the class :

$channel = new Mymodule_entries;
return $channel->entries(array(1));

And that’s all !

       
GDmac - expocom's avatar
GDmac - expocom
350 posts
14 years ago
GDmac - expocom's avatar GDmac - expocom

Just now found this after searching for extending the channel class. Thanks for posting your solution.

DMlogic made a blogpost explaining this a bit and options for altering tagdata before or after the channel module http://dmlogic.com/blog/extending-the-expression-engine-channel-module/

       

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.