3

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

Now, I want to be able to override erb templates by dropping in a .liquid file, which will render right off the controller action.

For example, I want to override app/views/pages/home.html.erb:

<h1><%= t 'it_works' %></h1>

...with app/themes/my_theme/views/pages/home.liquid

<h1>It works with {{ "liquid" }}</h1>

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/*)

Community
  • 1
  • 1
Kyle Macey
  • 8,074
  • 2
  • 38
  • 78

2 Answers2

3

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/

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.

joost
  • 6,549
  • 2
  • 31
  • 36
0

According to the documentation you can use prepend_view_path

Add the following to your ApplicationController:

before_filter :set_theme_path

def set_theme_path
  prepend_view_path "app/themes/#{current_theme}"
end

So Rails should then look for any views in your theme specific directory in preference to the default views in app/views/**/*

Andrew Hacking
  • 6,296
  • 31
  • 37
  • Yeah, I did that. But that only reads `erb` files. I want to use `liquid` instead of `erb`. – Kyle Macey Oct 10 '13 at 13:44
  • How are you naming your templates? They probably need to be named foo.html.liquid – Andrew Hacking Oct 11 '13 at 11:47
  • It's also a bit unfair to down vote an answer that is not wrong. As you admit you do what I posted. There could be a million things that are wrong with your environment that you have not disclosed or elaborated on in your question. – Andrew Hacking Oct 11 '13 at 11:52
  • It was fair to downvote since I had stated in my question that I was already using prepend_view_path. The answer didn't seem like it was from someone who actually took the time to understand the question. – Kyle Macey Oct 11 '13 at 13:35