zoukankan      html  css  js  c++  java
  • content_for对应的yield 小青年

    每天学一点,天天都是进步!

     content_for在次模板中使用,比如index.html.erb或者其他,对应的yield在主模板中使用,对于index.html.erb来说的application.html.erb中使用。

    在index.html.erb中有如下代码:

    <% content_for(:list) do %>

      <ol>

         <% for i in 1..5 %>

              <li>I'm <%= i %> !</li>

          <% end %>

      </ol>

    <% end %>

    然后在application.html.erb中的body中用yield来显示index中的content_for中的内容如下:

    <%= yield :list %>

     这个时候一定要指定是list这样才会显示,如果只是<%= yield %> 这样是不会去显示content_for(:list)里的内容的!

     实际上是yield通过传递的不同参数, 控制不同的代码块!

  • 相关阅读:
    php面向对象开发的学习
    我的php感悟
    说说面向对象
    session,上传文件
    PHP构造函数的用法分析
    生成图片
    上传文件
    fetch
    ajax2
    ajax1
  • 原文地址:https://www.cnblogs.com/perish/p/2682019.html
Copyright © 2011-2022 走看看