<p>The full list of events that Craft provides is documented <a href="http://buildwithcraft.com/docs/plugins/events-reference" rel="nofollow">here</a>.</p>

<p>There currently isn't <code>onBeforeRender</code> or <code>onRender</code> events, but it is on our list with no particular ETA.  It gets tricky because it's difficult to distinguish between the main template and any other template that might happen to call <a href="http://buildwithcraft.com/classreference/services/TemplatesService#render-detail" rel="nofollow">TemplateService->render()</a> (includes, etc.).</p>

CC BY-SA 3.0
2014-12-15T22:46:52.413Z
What about an onRequest event. Basically looking for any entry point where I can run some business logic.
David A McInnis
CC BY-SA 3.0
2014-12-15T22:49:06.807Z
Could I use the onLoadPluguns event?
David A McInnis
CC BY-SA 3.0
2014-12-15T23:21:27.603Z
Yii does have an onBeginRequest (http://www.yiiframework.com/doc/api/1.1/CApplication#onBeginRequest-detail), but both of those you listed will be fired on every request regardless of whether a template will render or not.
Brad Bell
CC BY-SA 3.0
2014-12-15T23:38:06.483Z
Forgive me if I'm way off, but the template is essentially being rendered on the server before it ever gets delivered to the client. Can't you call a service method (via a template variable wrapper) to do your pre-prossessing?
Douglas McDonald
CC BY-SA 3.0
2014-12-15T23:43:12.137Z
Yes... I'm just saying those events will get fired on *every* request, regardless of if a template would be rendered or not. An `onBeforeRender`/`onRender` event would imply a guarantee that a template would be rendered as well as some context as to which template was going to be/was rendered.
Brad Bell
CC BY-SA 3.0
2015-01-25T17:12:28.140Z
I also would like to get an event whereby the plugin gets notified when a page has been requested. How could I do this? More specifically, when an entry URL has been requested
Maria Stellini
CC BY-SA 3.0
2014-12-15T22:22:48.287Z
2014-12-15T23:41:09.160Z
2014-12-15T23:41:09.160Z
Brad Bell
<p>Based off the recommendations I am going to use the onLoadPlugins event. I can limit its execution of business logic based on the URL construct. At least until I get a better solution. This should work but assumes that the onLoadPlugins event fires with each page request.</p>

<p>Here is my code that appears to be working.</p>

<pre><code>public function init() 
{
    craft()-&gt;on('plugins.onLoadPlugins', function(Event $event) {
       $pageUrl = craft()-&gt;request-&gt;getSegments(); 
       if ( $pageUrl[0] != 'page' ) {
            // if not /page then exit here
            return;
       }

       // place business logic here
       echo "you're in;
       exit;

    });
 }   
</code></pre>

CC BY-SA 3.0
2015-01-25T17:21:14.790Z
Those this work for you? does not seem to work for me .. I would like to be notified when an entry is going to be loaded
Maria Stellini
CC BY-SA 3.0
2015-01-30T06:36:20.287Z
Yes, it did work for me. However I opted to write a twig extension instead. Cannot remember why I did that. Probably so that I could call it from random pages. Everything I need execute the code, I simply include {% entry.id | myTwigExtension %}. This might work for you too. Just include at top of page, then execute logic based on result.
David A McInnis
CC BY-SA 3.0
2014-12-16T00:07:37.667Z
2014-12-16T09:24:25.333Z
2014-12-16T09:24:25.333Z
David A McInnis
<p>I am looking for away to manipulate and record data about an entry before it is returned to the client. I could do this with AJAX after the page is rendered by the browser but I would prefer to do this on the server.</p>

<p>Is there an event or hook I can use to accomplish this?</p>

<plugin-development>
onBeforeRender event? Is there an event or hook I can use with my plugin?
# onBeforeRender event? Is there an event or hook I can use with my plugin?

(Asked by: username_0 on 2014-12-15)

I am looking for away to manipulate and record data about an entry before it is returned to the client. I could do this with AJAX after the page is rendered by the browser but I would prefer to do this on the server.

Is there an event or hook I can use to accomplish this?

**Tags:** plugin-development

---

## 2 answers

### Answer by username_1 on 2014-12-15. Score: 1

The full list of events that Craft provides is documented [here](http://buildwithcraft.com/docs/plugins/events-reference).

There currently isn't `onBeforeRender` or `onRender` events, but it is on our list with no particular ETA. It gets tricky because it's difficult to distinguish between the main template and any other template that might happen to call [TemplateService->render()](http://buildwithcraft.com/classreference/services/TemplatesService#render-detail) (includes, etc.).

> **Comments:**
> **username_0**: What about an onRequest event. Basically looking for any entry point where I can run some business logic.  
> **username_0**: Could I use the onLoadPluguns event?  
> **username_1**: Yii does have an onBeginRequest (http://www.yiiframework.com/doc/api/1.1/CApplication#onBeginRequest-detail), but both of those you listed will be fired on every request regardless of whether a template will render or not.  
> **username_2**: Forgive me if I'm way off, but the template is essentially being rendered on the server before it ever gets delivered to the client. Can't you call a service method (via a template variable wrapper) to do your pre-prossessing?  
> **username_1**: Yes... I'm just saying those events will get fired on *every* request, regardless of if a template would be rendered or not. An `onBeforeRender`/`onRender` event would imply a guarantee that a template would be rendered as well as some context as to which template was going to be/was rendered.  
> **username_3**: I also would like to get an event whereby the plugin gets notified when a page has been requested. How could I do this? More specifically, when an entry URL has been requested  

---

### Answer by username_0 on 2014-12-16. Score: 0

Based off the recommendations I am going to use the onLoadPlugins event. I can limit its execution of business logic based on the URL construct. At least until I get a better solution. This should work but assumes that the onLoadPlugins event fires with each page request.
Here is my code that appears to be working.
public function init() 
{
    craft()->on('plugins.onLoadPlugins', function(Event $event) {
       $pageUrl = craft()->request->getSegments(); 
       if ( $pageUrl[0] != 'page' ) {
            // if not /page then exit here
            return;
       }

       // place business logic here
       echo "you're in;
       exit;

    });
 }

> **Comments:**
> **username_3**: Those this work for you? does not seem to work for me .. I would like to be notified when an entry is going to be loaded  
> **username_0**: Yes, it did work for me. However I opted to write a twig extension instead. Cannot remember why I did that. Probably so that I could call it from random pages. Everything I need execute the code, I simply include {% entry.id | myTwigExtension %}. This might work for you too. Just include at top of page, then execute logic based on result.  

---

