Rails宝典之第八式: layout与content_for
来源:互联网 发布:nginx 4层负载均衡 编辑:程序博客网 时间:2024/05/22 06:05
如果我们想根据模板页面更改局部layout,使用content_for即可。
content_for允许模板页面代码放到layout中的任何位置。
比如我们的Rails程序不同的页面有不同的css样式,我们可以在layout里留出位置:
我们用yield :head来给模板页面某段代码留个"座位",再看页面:
content_for :head里面的代码将填充layout里的yield :head。
layout+content_for,很灵活吧。
content_for允许模板页面代码放到layout中的任何位置。
比如我们的Rails程序不同的页面有不同的css样式,我们可以在layout里留出位置:
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html>
- <head>
- <title>Todo List</title>
- <%= stylesheet_link_tag 'application' %>
- <%= yield :head %>
- </head>
- <body>
- <div id="container">
- <h1>Todo List</h1>
- <%= yield %>
- </div>
- </body>
- </html>
我们用yield :head来给模板页面某段代码留个"座位",再看页面:
- <% content_for :head do %>
- <%= stylesheet_link_tag 'projects' %>
- <% end %>
- <h2>Projects</h2>
- <ul>
- <% for project in @projects %>
- <li><%= project.name %></li>
- <% end %>
content_for :head里面的代码将填充layout里的yield :head。
layout+content_for,很灵活吧。
- Rails宝典之第八式: layout与content_for
- Rails宝典之第七式: layout详解
- rails yield与content_for
- layout与content_for
- 2007-07-29Rails宝典之第七式: layout详解
- 主题:Rails宝典之第七式: layout详解
- rails中 yeild 与 content_for之间的区别
- rails中 yeild 与 content_for之间的区别
- rails中 yeild 与 content_for之间的区别
- Rails宝典之第五式: 使用with_scope
- Rails宝典之第十五式: find条件
- Rails宝典之第十六式: 虚拟属性
- Rails宝典之第十八式: 循环flash
- Rails宝典之第二十式: 限制访问
- Rails宝典之第二十二式: eager loading
- Rails宝典之第二十三式: counter cache
- Rails宝典之第二式: 动态find_by方法
- Rails宝典之第三式: 通过关联做查询
- 月老啊
- 日期类的应用
- the end ,and the beginning
- Java NIO聊天窗口实例
- 基类
- Rails宝典之第八式: layout与content_for
- EFFECTIVE JAVA 笔记
- C语言设计之 学生信息管理系统
- hdoj 1330
- Asp.net MVC3 关于@Html中ListBox、DropDownList使用
- .NET环境下TextBox和RichTextBox透明背景色
- error C2491 definition of dllimport static data member not allowed(不允许dllimport静态数据成员的定义)
- LINUX系统学习笔记07-磁盘配额与磁盘阵列
- 正则表达式备忘-----------转载自http://www.cnblogs.com/KissKnife/archive/2008/03/23/1118423.html