My default templating engine is haml, but I would to sometimes change it to erb if i specify a specific parameter?
我的默认模板引擎是haml,但如果我指定一个特定的参数,我有时会将其更改为erb?
For example, I am pasting in some html code and would just like to test the code without HAML complaining about its format.
例如,我粘贴一些HTML代码,只想测试代码而不用HAML抱怨它的格式。
Any idea how to do this?
知道怎么做吗?
3 个解决方案
#1
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
并使用?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
并调用它?render = haml或?render = erb(或者没有,它将使用默认值
at the end of the controller's action that you are using
在你正在使用的控制器动作的最后
#2
0
Am I wrong that you simply need to save file as your_file.html.erb
instead of your_file.html.haml
?
我错了你只需要将文件保存为your_file.html.erb而不是your_file.html.haml?
#3
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.
如果你只是想使用不同的模板语言删除一些代码,那么我将它放在一个单独的部分中。在这种特殊情况下,这似乎最简单。
#1
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
并使用?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
并调用它?render = haml或?render = erb(或者没有,它将使用默认值
at the end of the controller's action that you are using
在你正在使用的控制器动作的最后
#2
0
Am I wrong that you simply need to save file as your_file.html.erb
instead of your_file.html.haml
?
我错了你只需要将文件保存为your_file.html.erb而不是your_file.html.haml?
#3
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.
如果你只是想使用不同的模板语言删除一些代码,那么我将它放在一个单独的部分中。在这种特殊情况下,这似乎最简单。