I want to pass a hash to the render method. In my console everything works fine when I do this:
@object = Object.find(params[:id])
@hash_object = @object.to_liquid
@template = Liquid::Template.parse("Welcome to {{object_title}}")
@template.render('object_title' => @hash_object["title"])
But when i want to render the page through my controller and pass it through an app-proxy which expects vanilla liquid, the hash-key isn't appearing. But it's interpreted, because the view shows blank space. If it wouldn't work at all, the view would show:"Welcome to {{object_title}}" or don't even load because of syntax errors.
I tried almost every possible way to render the template. The next two tryouts are the ones which do not throw an error, but show only a blank where the title should appear:
@pageview = Liquid::Template.parse(File.read(Rails.root + "app/views/app_proxy/show.html.erb"))
render text: @pageview.render('object_title' => @hash_object["title"]), content_type: "application/liquid"
And the second one (which I think is a bit cleaner and more rubylike):
respond_to do |format|
format.html do
render text: @pageview.render('object_title' => @hash_object["title"]), layout: false, content_type: "application/liquid"
end
end
Where is the mistake in these renderings or what am I missing?
@hash_object["title"]
does it returnString
or something else? It might be just the case that you tell it@hash_object["title"].to_s
. I haven't worked with Liquid though, but if for some reason it doesn't read your value from the key, Ruby might have interpreted it as something else. – mutantkeyboard.erb
file inside the Liquid and then use it to rendertext
. But my question is: What happens if you render raw file instead, so insteadrender text
placerender file
? I'm really not used too much to other templating engines apart from HAML and ERB, so this might not be the best advice ever. – mutantkeyboard