我在将数据传递给 Slim 模板时遇到问题。我有以下工作代码(使用来自此 SO 线程的信息):
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
我的问题是在我的情况下如何将参数传递给布局模板?