Question

I want to create a Ruby on Rails layout and it should be in Liquid format.

Basically what I'm trying to do is to let the users to create their own layouts and save them in the database.

I tried to use <%= Liquid::Template.parse(<code from database>).render %> in my layout.erb file but there I can't use the 'yield' command (since this is a layout I should have to have a way of rendering pages.)

But when I use 'layout.liquid' with {{ content_for_layout }} is will work find BUT, cannot load details from the database (I mean the HTML code..)

I hope I made myself clear :D )

Was it helpful?

Solution

Take a look at this Ruby on Rails plug-in:

http://github.com/akitaonrails/dynamic_liquid_templates

Next we have to find a way to intercept the default Ruby on Rails behaviour for your controller.

class MyAwesomeController
  layout :get_my_db_layout
  ....
  protected
  def get_my_db_layout
    'as_if_by_a_miracle.liquid' # add your db finder here        
  end
end

Then, overwrite LocalFileSystem#read_template_file with your own class / method, to get the template from the database. LocalFileSystem#read_template_file is a Liquid class.

I hope, that this idea is helpful.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top