2013-02-17 54 views
2

將數據傳遞給Slim模板時遇到問題。我有工作代碼(使用this SO thread信息)以下:使用Slim-lang將數據傳遞給佈局模板

l = Slim::Template.new { @layout } # How to pass data here? 

_p = Slim::Template.new { @post_text }.render(Object.new, :post => post) 
# Here passing data (post) works fine  -----------------^ 

out = l.render{ _p } 

我有什麼模板:

layout.slim

doctype 
    html 
    head 
    title =my_title # < I cannot pass any parameters to this file 
    body 
    ==yield 

post_text.slim

-unless post.nil? 
    h1 =post[:title] 
    hr 
    =post[:text] 
-else 
    h2 No posts 

我的問題是如何將參數傳遞給佈局模板在我的情況?

+0

所以無法調用最後呈現世界投資報告選項?像'''l.render(Object.new,:my_title =>'bla'){_p}''' – phoet 2013-02-17 18:28:43

回答

1

phoet應該寫一個答案他的意見,因爲它幫助:

l.render(Object.new, :my_title => 'bla') { _p }