<?php | |
class ExtendedChannel { | |
public __construct() | |
{ | |
$this->EE = &get_instance(); | |
} | |
public function extended_entries() | |
{ | |
// Get params | |
$some_param = $this->EE->TMPL->fetch_param('some_param'); | |
// Do something to get some custom data, in this case $entry_ids was an array of entry IDs | |
// ... | |
// Modify the template params | |
$entry_ids = implode('|', $entry_ids); | |
$this->EE->TMPL->tagparams['fixed_order'] = $entry_ids; | |
// Include the class if it isn't included | |
if(!class_exists('Channel')) | |
{ | |
// First party modules or plugins | |
require_once(APPPATH.'modules/channel/mod.channel.php'); | |
// Third party would be | |
// require_once(PATH_THIRD.'package/mod.package.php'); | |
} | |
// Create instance of Package class and call the tag you want to extend | |
// It will use the parameters passed from the template, as well as | |
// anything you have modified in tagparams | |
$C = new Channel(); | |
$this->return_data = $C->entries(); | |
return $this->return_data; | |
} | |
} |
This comment has been minimized.
This comment has been minimized.
Hey, that's cool. I have been dynamically outputting a channel entries tag, which was then parsed again by EE. I bet your way is more efficient. |
This comment has been minimized.
This comment has been minimized.
Yes, it would be a tiny bit more efficient to call the class directly the way I am doing. The main difference would be in the regex to find the generated {exp:channel:entries} tag and parse it's parameters. I feel like calling the class directly is much more testable and easier to work with however, even if it is only a bit faster. |
This comment has been minimized.
This comment has been minimized.
This is really helpful, thanks for posting! However, I notice that when modifying
Still returns entries without "foo" in the title. I know it's been a while since you posted this, but if in your experience you've ever come across this issue, I'd love to know how you got around it. |
This comment has been minimized.
Of course this won't work in every situation as it requires that a parameter or set of parameters to the existing tag can accomplish what you want, but it can help simplify complex bits of template code and make things a lot more efficient if you are doing a lot of work just to pass off the final query to an existing module or plugin.
The fixed_order parameter is particularly useful for extending the {exp:channel:entries} tag since it allows you to specify an exact set of entries to return without any further work. You can do all kinds of crazy stuff using this as a basis.