0

My default templating engine is haml, but I would to sometimes change it to erb if i specify a specific parameter?

For example, I am pasting in some html code and would just like to test the code without HAML complaining about its format.

Any idea how to do this?

Kamilski81
  • 14,409
  • 33
  • 108
  • 161
  • Related questions: http://stackoverflow.com/questions/339130/how-do-i-render-a-partial-of-a-different-format-in-rails, http://stackoverflow.com/questions/6125265/using-layouts-in-haml-files-independently-of-rails. – Todd A. Jacobs Jun 07 '12 at 16:56

3 Answers3

3

do something like:

if params[:render_erb]
  render 'file.html.erb'
else
  render 'file.html.haml'
end

and call the action with ?render_erb=true

or

render "file.html.#{params[:render]}" ir params[:render]

and call it ?render=haml or ?render=erb (or nothing and it will use the default

at the end of the controller's action that you are using

arieljuod
  • 15,460
  • 2
  • 25
  • 36
  • I tried this and it doesnt switch to the haml version ever... render "connect.html.erb" OR render "connect.html.haml" – Kamilski81 Jun 07 '12 at 17:34
  • 1
    I think it has to be render :file => '/path/to/file', note that it needs an absolute system path not a relative path and you'll have to specify :layout => true as well! – DVG Jun 07 '12 at 17:47
  • You are correct, please edit your answer above to have :file => "" – Kamilski81 Jun 07 '12 at 20:56
  • the :file => and the absolute path depends on the file you want to render, check here http://guides.rubyonrails.org/layouts_and_rendering.html#using-render – arieljuod Jun 08 '12 at 19:04
0

Am I wrong that you simply need to save file as your_file.html.erb instead of your_file.html.haml?

Hauleth
  • 22,873
  • 4
  • 61
  • 112
  • Well I did that but now it picks up my erb every time, I want that part to be conditional... if X use HAML else use ERB?? – Kamilski81 Jun 07 '12 at 17:31
0

You can use different templates in the same application, and you can use different template engines for views, partials, and layouts, but as far as I know you can't duck in and out of multiple template engines within the same template file.

If you just want to drop some code in using a different template language, then I'd put it in a separate partial. That certainly seems easiest in this particular case.

Community
  • 1
  • 1
Todd A. Jacobs
  • 81,402
  • 15
  • 141
  • 199
  • I am not referring to using different engines in same template file, i just want to input a condition in my controller of saying "use erb version" OR "use haml version" – Kamilski81 Jun 07 '12 at 17:35