<p>So I found the answer i was looking for.</p>

<p>It looks like if you add a prepValue function to your fieldtypes class it can perform any action you want on the value from your custom field before returning it to the template</p>

<p>Looks something like this</p>

<pre><code>class PLUGINNAME_FIELDNAMEFieldType extends BaseFieldType
{
    public function getName()
    {
        return Craft::t('My Field\'s Name');
    }

...
    public function prepValue($value)
    {
      // do stuff with value here like create a model, or just some conversion
      $newValue = $value." &lt;strong&gt;it works!&lt;/strong&gt;";

      // newValue is whats returned to the template when you access via entry.customFieldName
      return TemplateHelper::getRaw($newValue);

      // Note: TemplateHelper::getRaw isnt required it just included cause the newValue includes html that i want to render on the page, default behavior is to escape all html

    }

}
</code></pre>

CC BY-SA 3.0
2014-08-13T23:39:40.613Z
2014-08-13T23:39:40.613Z
Keith Mancuso
<p>Run your HTML string through <code>getRaw</code> before sending it back to the template...</p>

<pre><code>return TemplateHelper::getRaw($output);
</code></pre>

<p>This will basically "pre-raw" your HTML string.</p>

CC BY-SA 3.0
2014-08-13T16:43:51.817Z
nice! that takes care of that one. any thoughts on returning the html directly throught the field variable?  is that even possible?
Keith Mancuso
CC BY-SA 3.0
2014-08-13T16:42:01.020Z
2014-08-13T16:42:01.020Z
Lindsey D
<p>Is it possible to control what gets output in the template a custom fieldtype?</p>

<p>For example im working on a eventbrite plugin and it saves the id in the database but I want the field in the template to return a fully formatted register button.</p>

<p>Right now im doing this with a craft variable that i'm passing the id and returns the html for the button into but feels like there might be a simpler way?</p>

<hr>

<p>Related to that right now i have to add | raw to the variable output</p>

<p>so its </p>

<pre><code>{{ craft.eventBrite.registerButton(entry.eventbriteId) | raw }}
</code></pre>

<p>is there a way to prevent the escaping of whats being returned without the extra filter in the template?</p>

CC BY-SA 3.0
2014-08-13T17:00:59.350Z
I'm confused about the first part of your question... You want your field to automatically determine if an entry has already been loaded (ie: dynamic entry URLs)? It looks to me like you're already doing it right... How else would your `registerButton` know which `eventbriteId` it was working with?
Lindsey D
CC BY-SA 3.0
2014-08-13T18:55:57.153Z
I guess i mean instead of making the customfield just be the id that the logic for the button could be in the field and output would come just by accessing the custom field... more like what dukt is doing wiht the video plugin for example.. https://dukt.net/craft/videos/docs/video-fields
Keith Mancuso
CC BY-SA 3.0
2014-08-13T18:59:40.467Z
ahh looks like its the prepValue function in the fieldtype is what im looking for, lets you change the value saved in the database into whatever you want like an object with sub values
Keith Mancuso
CC BY-SA 3.0
2014-10-15T07:54:15.187Z
I came across this question while searching for Event Brite plugins for CraftCMS...

Will your Event Brite plugin be available for commercial or public use?
Sean Delaney
<plugin-development><custom-fieldtype>
How do you customize what value a Custom FieldType returns to a template
# How do you customize what value a Custom FieldType returns to a template

(Asked by: username_0 on 2014-08-13)

Is it possible to control what gets output in the template a custom fieldtype?
For example im working on a eventbrite plugin and it saves the id in the database but I want the field in the template to return a fully formatted register button.
Right now im doing this with a craft variable that i'm passing the id and returns the html for the button into but feels like there might be a simpler way?

Related to that right now i have to add | raw to the variable output
so its 
{{ craft.eventBrite.registerButton(entry.eventbriteId) | raw }}

is there a way to prevent the escaping of whats being returned without the extra filter in the template?

**Tags:** plugin-development, custom-fieldtype

> **Comments:**
> **username_1**: I'm confused about the first part of your question... You want your field to automatically determine if an entry has already been loaded (ie: dynamic entry URLs)? It looks to me like you're already doing it right... How else would your `registerButton` know which `eventbriteId` it was working with?  
> **username_0**: I guess i mean instead of making the customfield just be the id that the logic for the button could be in the field and output would come just by accessing the custom field... more like what dukt is doing wiht the video plugin for example.. https://dukt.net/craft/videos/docs/video-fields  
> **username_0**: ahh looks like its the prepValue function in the fieldtype is what im looking for, lets you change the value saved in the database into whatever you want like an object with sub values  
> **username_2**: I came across this question while searching for Event Brite plugins for CraftCMS...  Will your Event Brite plugin be available for commercial or public use?  

---

## 2 answers

### Answer by username_0 on 2014-08-13. Score: 2 | Accepted answer

So I found the answer i was looking for.
It looks like if you add a prepValue function to your fieldtypes class it can perform any action you want on the value from your custom field before returning it to the template
Looks something like this
class PLUGINNAME_FIELDNAMEFieldType extends BaseFieldType
{
    public function getName()
    {
        return Craft::t('My Field\'s Name');
    }

...
    public function prepValue($value)
    {
      // do stuff with value here like create a model, or just some conversion
      $newValue = $value." it works!";

      // newValue is whats returned to the template when you access via entry.customFieldName
      return TemplateHelper::getRaw($newValue);

      // Note: TemplateHelper::getRaw isnt required it just included cause the newValue includes html that i want to render on the page, default behavior is to escape all html

    }

}


---

### Answer by username_1 on 2014-08-13. Score: 4

Run your HTML string through getRaw before sending it back to the template...
return TemplateHelper::getRaw($output);

This will basically "pre-raw" your HTML string.

> **Comments:**
> **username_0**: nice! that takes care of that one. any thoughts on returning the html directly throught the field variable?  is that even possible?  

---

