开发者

rails3 + liquid parse question

开发者 https://www.devze.com 2023-01-25 23:59 出处:网络
I have a question in using luquid. My question is like this, I have a model called \'Page\' (with is an ActiveRecord::Base

I have a question in using luquid. My question is like this,

I have a model called 'Page' (with is an ActiveRecord::Base inherited) , and it has a column called 'content' which will store the html page content.

I have a code to display it as follows

<%开发者_如何学JAVA@template = Liquid::Template.parse(page_content) %> 
<%=  @template.render('page_content' => yield)  %> 

where 'page_content' has implemented in application helper as follows

def current_site_layout 
    Page.find(1). content 
end 

but my problem is if I have content as follows

<h1>This is a test</h1>

It will display in the page as

<h1>This is a test</h1> (with <h1></ h1> tags)

where as I want it to print like

This is a test

(formatting applied as h1)

what am I missing here , and I think I will have to use liquid_methods or something like that. But since I'm new to liquid I'm not sure which method to use.. can someone help me

I'm on rails3 and using gem 'liquid 2.2.2', from 'github.com/GnomesLab/ liquid.git'

thanks in advance

cheers

sameera


In rails 3, strings are escaped by default. To display unescaped strings, you need to call raw method explicitly.

<%@template = Liquid::Template.parse(page_content) %> 
<%=  raw @template.render('page_content' => yield)  %>
0

精彩评论

暂无评论...
验证码 换一张
取 消