Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-15T22:46:52.413Z
Answers.Text: What about an onRequest event. Basically looking for any entry point where I can run some business logic.
Answers.UserDisplayName: David A McInnis
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-15T22:49:06.807Z
Answers.Text: Could I use the onLoadPluguns event?
Answers.UserDisplayName: David A McInnis
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-15T23:21:27.603Z
Answers.Text: 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.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-15T23:38:06.483Z
Answers.Text: 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?
Answers.UserDisplayName: Douglas McDonald
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-15T23:43:12.137Z
Answers.Text: 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.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-25T17:12:28.140Z
Answers.Text: 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
Answers.UserDisplayName: Maria Stellini
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-15T22:22:48.287Z
Answers.LastActivityDate: 2014-12-15T23:41:09.160Z
Answers.LastEditDate: 2014-12-15T23:41:09.160Z
Answers.UserDisplayName: Brad Bell
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-25T17:21:14.790Z
Answers.Text: 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
Answers.UserDisplayName: Maria Stellini
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-30T06:36:20.287Z
Answers.Text: 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.
Answers.UserDisplayName: David A McInnis
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-16T00:07:37.667Z
Answers.LastActivityDate: 2014-12-16T09:24:25.333Z
Answers.LastEditDate: 2014-12-16T09:24:25.333Z
Answers.UserDisplayName: David A McInnis
Body: <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>
  
Tags: <plugin-development>
Title: onBeforeRender event? Is there an event or hook I can use with my plugin?
ThreadText: # 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.  
  
  ---
  
  