3

I've been trying to render a underscore.js template, that is just like ERB on some haml content.

But as the templates grow I dont want to do more like this

%script{:type => "text/template", :id => "my_template"}
  :plain
    <div><%= my_js_value %></div>
    .....(other content)...

and instead of that I want to use partials to render inside it I wish to do something like:

  %script{:type => "text/template", :id => "my_template"}
    =render :file => "mytemplate.txt"

But that rendering tried to bind the ERB on it, and I've got errors for my_js_value

The only way I get to do this rendering is through that way:

  %script{:type => "text/template", :id => "my_template"}
    =render :text => File.read("#{Rails.root}/app/views/mycontroller/mytemplate.txt")

The last one worked for me, but I was looking for something better than that.

What do you suggest me to do instead of reading a file? Isn't there a "raw" option for render?

BTW this is on a rails 2.3.14 app

mu is too short
  • 426,620
  • 70
  • 833
  • 800
AndreDurao
  • 5,600
  • 7
  • 41
  • 61

1 Answers1

-1

I don't know HAML to well yet but there is a raw option for rails. You can find the details at the link below:

<%= raw @user.name %>

http://api.rubyonrails.org/classes/ActionView/Helpers/OutputSafetyHelper.html

Shaun Frost Duke Jackson
  • 1,256
  • 1
  • 10
  • 22