Answers.Body: <p>There is no event or hook that I'm aware of that can intercept the template rendering process directly. You would likely need to instigate this from within your template. I would suggest perhaps using a <a href="http://buildwithcraft.com/docs/plugins/variables">plugin variable</a> either directly, or as a wrapper for your <a href="http://buildwithcraft.com/docs/plugins/services">plugin service</a> method (if you need to do something more complicated). </p>
  
  <p>Something like the following:</p>
  
  <p>Note: This is adapted from the '<a href="http://straightupcraft.com/craft-plugins/business-logic-template">BusinessLogicTemplate</a>' plugin which provides a great starting point for plugin development.</p>
  
  <pre><code>&lt;?php namespace Craft;
  
  class MyPluginVariable
  {
  
      /**
       * Whatever you want to output to a Twig tempate
       * can go into a Variable method.
       *
       * HOW TO USE IT
       * From any Twig template, call it like this:
       *
       *     {{ craft.myPlugin.exampleVariable }}
       *
       * Or, if your variable requires input from Twig:
       *
       *     {{ craft.myPlugin.exampleVariable(twigValue) }}
       *
       */
      public function exampleVariable($optional = null)
      {
          return "And away we go to the Twig template...";
      }
      public function formatBody($body)
      {
          /* process $body and return it to the template */
          return $body;
      }
  
  }
  </code></pre>
  
  <p>Then in your template:</p>
  
  <pre><code>{{ craft.myPlugin.formatBody(entry.body) }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-28T23:18:55.023Z
Answers.Text: This is EXACTLY the kind of functionality I was looking for. Works perfect! Thank you x100000000
Answers.UserDisplayName: taylor
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-28T22:12:09.333Z
Answers.LastActivityDate: 2015-01-28T22:12:09.333Z
Answers.UserDisplayName: Douglas McDonald
Body: <p>I'd like to run the entry.body content through some PHP functions before the template outputs it, there probably two approaches to this:</p>
  
  <ol>
  <li><p>Create a twig function via Plug (if possible) and use that in template like:</p>
  
  <pre><code>{{ MyFunction( entry.body ) }}
  </code></pre></li>
  <li><p>Have function automatically grab the "body" of the current page, run through functions, and update it before template runs it. I'd prefer this method although but have no clue how to go about it.</p></li>
  </ol>
  
  <p>What would be the best approach -- and does anyone have any pointers / samples on how it'd be done? I've been digging through documentation but am struggling to find how to get the current entry.body through a plugin, or how to update it (just for the page rendering + template, not in database.)</p>
  
Tags: <plugin-development><entry><php>
Title: Update entry.body from Plugin
ThreadText: # Update entry.body from Plugin
  
  (Asked by: username_0 on 2015-01-28)
  
  I'd like to run the entry.body content through some PHP functions before the template outputs it, there probably two approaches to this:
  
  1. Create a twig function via Plug (if possible) and use that in template like:
  
     ```
     {{ MyFunction( entry.body ) }}
  
     ```
  2. Have function automatically grab the "body" of the current page, run through functions, and update it before template runs it. I'd prefer this method although but have no clue how to go about it.
  
  What would be the best approach -- and does anyone have any pointers / samples on how it'd be done? I've been digging through documentation but am struggling to find how to get the current entry.body through a plugin, or how to update it (just for the page rendering + template, not in database.)
  
  **Tags:** plugin-development, entry, php
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-01-28. Score: 6 | Accepted answer
  
  There is no event or hook that I'm aware of that can intercept the template rendering process directly. You would likely need to instigate this from within your template. I would suggest perhaps using a [plugin variable](http://buildwithcraft.com/docs/plugins/variables) either directly, or as a wrapper for your [plugin service](http://buildwithcraft.com/docs/plugins/services) method (if you need to do something more complicated).
  
  Something like the following:
  
  Note: This is adapted from the '[BusinessLogicTemplate](http://straightupcraft.com/craft-plugins/business-logic-template)' plugin which provides a great starting point for plugin development.
  
  ```
  <?php namespace Craft;
  
  class MyPluginVariable
  {
  
      /**
       * Whatever you want to output to a Twig tempate
       * can go into a Variable method.
       *
       * HOW TO USE IT
       * From any Twig template, call it like this:
       *
       *     {{ craft.myPlugin.exampleVariable }}
       *
       * Or, if your variable requires input from Twig:
       *
       *     {{ craft.myPlugin.exampleVariable(twigValue) }}
       *
       */
      public function exampleVariable($optional = null)
      {
          return "And away we go to the Twig template...";
      }
      public function formatBody($body)
      {
          /* process $body and return it to the template */
          return $body;
      }
  
  }
  
  ```
  
  Then in your template:
  
  ```
  {{ craft.myPlugin.formatBody(entry.body) }}
  
  ```
  
  > **Comments:**
  > **username_0**: This is EXACTLY the kind of functionality I was looking for. Works perfect! Thank you x100000000  
  
  ---
  
  