# Rendering a partial without evaluating the erb tags

**URL:** <https://discuss.rubyonrails.org/t/rendering-a-partial-without-evaluating-the-erb-tags/42659>\
**Category:** rubyonrails-talk\
**Created:** [May 19, 2009, 7:45pm UTC](https://discuss.rubyonrails.org/t/rendering-a-partial-without-evaluating-the-erb-tags/42659 "2009-05-19T19:45:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [May 19, 2009, 7:45pm UTC](https://discuss.rubyonrails.org/t/rendering-a-partial-without-evaluating-the-erb-tags/42659/1 "2009-05-19T19:45:21Z")

</div>

Hi, I have a partial (\_contact.html) which looks something like this

\<script id="contact\_template" type="text/html"\> &nbsp;&nbsp;\<h2\>\<%= contact.name %\>\</h2\> &nbsp;&nbsp;\<p\>\<%= contact.id %\>\</p\> \</script\>

I want to render this to the view exactly as it is show there. I don't want the erb tags evaluating. When I try and render this using: render :partial =\> 'contact.html'

I get an error because it is trying to evaluate the erb tags and call the name method on the non-existent contact object. I simply want to render the text, as it is written, to the view. How can I do this?

The reason for it is that I am investigating ways of JSON templating ([John Resig - JavaScript Micro-Templating](http://ejohn.org/blog/javascript-micro-templating/)). I am ultimately aiming to make some of my partials reuseable between the rails code and the javascript code so that I only have to maintain them in one place. I want to carry on using \<%= %\> in the JSON templates. How can I tell rails just to render the partial as text and not try to evaluate it? Thanks

---

<div class="post-metadata">

**Author:** ![pepe1](https://avatars.discourse-cdn.com/v4/letter/p/dec6dc/32.png) [@pepe1](https://discuss.rubyonrails.org/u/pepe1)\
**Post date:** [May 20, 2009, 12:42pm UTC](https://discuss.rubyonrails.org/t/rendering-a-partial-without-evaluating-the-erb-tags/42659/2 "2009-05-20T12:42:44Z")

</div>

The only way I would think you can do it is by reading the template file into a variable in your controller and in your view escaping the string.

Not pretty.

Pepe

---

<div class="post-metadata">

**Author:** ![Colin\_Law1](https://avatars.discourse-cdn.com/v4/letter/c/91b2a8/32.png) [@Colin\_Law1](https://discuss.rubyonrails.org/u/Colin_Law1)\
**Post date:** [May 20, 2009, 1:01pm UTC](https://discuss.rubyonrails.org/t/rendering-a-partial-without-evaluating-the-erb-tags/42659/3 "2009-05-20T13:01:54Z")

</div>

> The only way I would think you can do it is by reading the template
> 
> file into a variable in your controller and in your view escaping the
> 
> string.
> 
> Not pretty.
> 
> Pepe

I think that having once read the template file into a variable in the controller it can be displayed without escaping in the view. The string will not be parsed as erb

Colin
