Accessing liquid variable in erb template

17 views
Skip to first unread message

Greg DeVore

unread,
Oct 24, 2009, 8:15:45 PM10/24/09
to Liquid Templates
I am setting up a system where users can have a simple "wrapper"
liquid template and then we insert the content. So a simple liquid
file would look like:

<html>
<body>
<div id="wrapper">
{{ content_for_layout }}
</div>
</body>
</html>

What I would like to do is let users set a variable using liquid that
affects the content_for_layout. So for example:

<html>
<body>
{% assign show_authors = 'true' %}
<div id="wrapper">
{{ content_for_layout }}
</div>
</body>

And then the erb template that gets rendered for content_for_layout
might look like this:

<% @posts.each do |post| %>
<h2><%= @post.title %></h2>
<%= @post.author if show_authors == 'true' %>
<% end %>

Is this possible?

Thanks,
Greg DeVore

</html>

Simon Russell

unread,
Oct 27, 2009, 4:34:26 AM10/27/09
to liquid-t...@googlegroups.com
So basically you're letting users design a layout, which you want to
render the actions into?

Greg DeVore

unread,
Oct 27, 2009, 1:36:04 PM10/27/09
to Liquid Templates
Exactly.

Greg

Simon Russell

unread,
Oct 27, 2009, 7:01:58 PM10/27/09
to liquid-t...@googlegroups.com
Okay, well, thinking about it quickly, it's not looking nice, but it
will work. I'm sure there's a nicer way, however. Basically, you
might write your views normally, then write a standard layout that
just renders the Liquid template manually. Making the variables from
the Liquid template available would be a bit fiddly however (because
the easiest way to do things would be to render the Liquid template
after everything else). I might have to have a think...
Reply all
Reply to author
Forward
0 new messages