问题描述
我已使用prepend_view_path
在此处中将主题目录添加到我的应用中.它按预期工作.我现在可以在app/themes/my_theme/views
I've added a theming directory to my app as described here, using prepend_view_path
. It works as expected. I can now add a view structure in my app under app/themes/my_theme/views
现在,我希望能够通过放入.liquid
文件来覆盖erb
模板,该文件将立即显示控制器动作.
Now, I want to be able to override erb
templates by dropping in a .liquid
file, which will render right off the controller action.
例如,我要覆盖app/views/pages/home.html.erb
:
<h1><%= t 'it_works' %></h1>
...和app/themes/my_theme/views/pages/home.liquid
<h1>It works with {{ "liquid" }}</h1>
我不想指定一个视图路径数组(将很糟糕),而只需将.liquid
作为一个层添加到模板引擎中.但是,也许有一个不可覆盖的受保护视图黑名单(例如app/views/admin/*
)
I don't want to have to specify an array of view paths (upkeep would be awful), but just add .liquid
as a layer to the templating engine. Maybe, however, have a blacklist of protected views that cannot be overridden (such as app/views/admin/*
)
推荐答案
您有液体模板处理程序吗?否则,Rails将不知道您要使用.liquid文件做什么.请参阅此博客文章: http://royvandermeij.com/blog/2011/09/21/create-a-liquid-handler-for-rails-3-dot-1/
Do you have a liquid template handler? Otherwise Rails won't know what you want to do with .liquid files. See this blog post: http://royvandermeij.com/blog/2011/09/21/create-a-liquid-handler-for-rails-3-dot-1/
关于第二个问题:不为app/views/admin/*
使用主题,应确保您拥有一个不prepend_view_path
的AdminController.
For your second question: not using a theme for app/views/admin/*
you should make sure you have an AdminController that does not prepend_view_path
.
这篇关于如何用液体覆盖erb?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!