I'm new to hooks, so pardon any ignorance in the questions...

So in my extension, (ext.staree.php), I have the following specifying the hook:

class Staree_ext
    public $hooks = array('channel_entries_row');

Then in the activation method, I have this:

public function activate_extension()
    foreach ($this->hooks as $hook)
        $data = array(
            'class'     =>  __CLASS__,
            'method'    =>  'get_current_entry_id',
            'hook'      =>  $hook,
            'settings'  =>  serialize($this->settings),
            'priority'  =>  10,
            'version'   =>  $this->version,
            'enabled'   =>  'y'

        // insert in database
        ee()->db->insert('extensions', $data);

The get_current_entry_id is as follows: (Just to test right now)

public function get_current_entry_id($obj, $row)
    echo "<pre>";
    echo "</pre>";

This gives me the following:

    [entry_id] => 30
    [channel_id] => 5
    [forum_topic_id] => 
    [author_id] => 1
    [ip_address] => ::1

I need to get the current entry_id from my module mod.staree.php.

So inside my Staree class, I have the following method:

public function star()
    $testID = // (THIS is where I need the current id from the ext)    

    $test = "Static return: 1, Passed Entry Id: ".ee()->TMPL->fetch_param('entry_id').", Dynamically Pulled Entry Id: ".$testID;

    return $test;

I know if I pass the {entry_id} like this: {exp:staree:star entry_id="{entry_id}"}, it will work by fetching the params, but I would like to just get it from the template wherever it is.

I'm close, but not used to working with hooks. Any help would be GREAT!


1 Answer 1


It's not going to work how you're wanting. The template parser is first going to parse {exp:channel:entries} and output all the entries, and THEN parse your staree module. So by the time your module parses, the channel entries parser is already finished outputting all the entries it's going to output and is out of the picture, so current entry ID isn't available to the module tag. But it is available to the extension as you see there, but you're not going to be able to get it at parse time within the module.

  • Thanks for taking place... The reason I went this route is due to a response from a tweet I posted that EllisLab responded to. I think, but not sure @derek-jones nudged it in this direction. Not sure I follow your parse logic though. If you could expand a little it might help. I thought I understood the template parsing order, but if the extension is hooking into the channel_entries_row, is that not an entrance point in which I could pass the entry_id for each entry loop? (Whether I store it or just pass it?)
    – W3bGuy
    Sep 12, 2016 at 15:21
  • Yes Derek was probably going on the idea that your only objective was getting the current entry ID and not needing to pass it to a module tag. And yes EE's parser is a little different in that it's breadth first instead of depth first, so that's why it behaves this way. Your extension will fire for all entry rows before your module file is called, which is what makes this difficult. You could theoretically collect the entry IDs in some sort of session cache for your module to consume and then assume your module is going to be called in the same order, but that may be a little janky.
    – Kevin Cupp
    Sep 12, 2016 at 15:34
  • Is there a reason you don't want your templates to be explicit in passing in the entry ID though? It's typically good practice.
    – Kevin Cupp
    Sep 12, 2016 at 15:34
  • I agree in the good practice bit... I was basically using this to learn about hook usage. I just can't find anything good online about using them. The docs are vague at best. I had a different post about the initial usage here which was responded to. I am pretty sure the usage I was after was clear there. Maybe it was a misunderstanding. I just figured I would start this question with hooks only. expressionengine.stackexchange.com/questions/38100/…
    – W3bGuy
    Sep 12, 2016 at 15:38
  • Ah ok I see, I can respond to your other question to try to clarify hook usage.
    – Kevin Cupp
    Sep 12, 2016 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.