views:

752

answers:

3

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 )

+1  A: 

Hi, please read Tobis article on

http://wiki.github.com/tobi/liquid/getting-liquid-to-work-in-rails

or look at this screencast

http://railscasts.com/episodes/118-liquid

crazyrails
Hi crazyrails,thanks for your reply. But my question remains :( , coz I want to keep my layout code in the database. (Ex: <html> .. </html>)But my problem is , since rails layout has <%= yield%> method, i cant do it in my layout.erb fileA;m I doing something wrong here, or is there any alternative thanks again..
sameera207
Maybe - this is what you want: Build a controller with an index action. In the controller you have to put all the Liquid::Template.parse(<code from database>).render things an assign it to a @output variable. In the index view call <%= @output %>.
crazyrails
A: 

@Peter - Hi, yes I'm referring to liquidmarkup.org :D

@crazyrails - Hi, thanks for the reply, Yeah your solution will work for view's, But what I'm trying to do here is trying to create a layout inside (app/view/layouts), So when creating a layout i cant call the 'yield' method If i store the code in the database (Ex : .. ), I'm sorry if i made things complecated :D. thanks again for your effort, any ideas ?!!

cheers, sameera

sameera207
@sameera207: You should be able to add comments as direct replies to Peter and crazyrails. Look for the "add comment" link at the bottom left of the question and each answer.
Bill the Lizard
Hi Bill the LizardSorry my bad. Still getting used to stackoverflow :)
sameera207
+1  A: 

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.

crazyrails