Suppose I have a template with a channel entries tag on it. I need to execute an extension method during a hook that runs before the channel entries query takes place. It doesn't matter what parameters are passed to the hook, I just need to execute some logic any time entries are going to be queried.
2 Answers
It sounds like the channel_entries_row hook would do it? http://ellislab.com/expressionengine/user-guide/development/extension_hooks/module/channel/index.html#channel-entries-row
-
I believe that hook executes after the channel module runs the query and executes once per entry in the results. Commented Jan 30, 2013 at 18:42
-
channel_entries_query_result gets called once per entries tag, and the tag contents are not parsed yet. edit: but you said BEFORE the query takes place, so disregard this comment. Commented Jan 30, 2013 at 18:49
-
1You might be able to use template_fetch_template and use $row['template_data'] which I think has the full unparsed template contents? You can't return a modified version of template_data though. Then you could use a regex to see if an entries tag exists: preg_match('/{exp:channel:entries(.*)?(?:}.*){\/exp:channel:entries}/s', $row['template_data'], $matches); Commented Jan 30, 2013 at 18:54
-
1It looks like I am just going to go with template_fetch_template because I don't think there are any channel module hooks that execute prior to the query. Commented Jan 30, 2013 at 18:55
We should make a feature request. I need a hook that runs before the query is ran too. To my knowledge, such hook does not exist.
-
1At first, we used the template_fetch_template hook but it wasn't a good kludge because then our hook logic would execute once for every embed which was overkill. In the end, we went with a core hack and created a new hook. Commented Feb 22, 2013 at 21:12
-
Is there somewhere we can submit feature requests to EllisLab? Can't seem to find one. Commented Apr 5, 2013 at 18:57