如何将变量传递到布局? [英] How to pass a variable to a layout?
本文介绍了如何将变量传递到布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个版本的应用程序布局,仅在几行中有所不同.考虑以下示例:
I have a two versions of my application layout, which are differs only in a few lines. Consider following example:
!!!
%html
%head
# a lot of code here
%body
# some more code here
- if defined? flag and flag == true
# variant 1
- else
# variant 2
问题是,如何将这个标志传递给布局?
The question is, how do I pass this flag to the layout?
class ApplicationController < ActionController::Base
layout 'layout', :locals => {:flag => true} #won't work :(
# ...
end
推荐答案
控制器实例变量?这是将信息获取到模板的正常方法.
A controller instance variable? That's the normal way to get information to the template.
这篇关于如何将变量传递到布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文