【问题标题】:rails 4 merge 2 content for together?rails 4将2个内容合并在一起?
【发布时间】:2014-07-06 07:22:43
【问题描述】:

我有各种页面需要在顶部多个content_for,即:

- content_for :title, AppConfig.product['slogan']
- content_for :class, 'brand'

在我的布局中使用:

== render 'layouts/top_wrapper'

  main[class="view-#{yield(:class)}-wrapper"]
    section[class="content-outer-wrapper"]
      div[class="row"]
        div[class="large-12"]
          div[class="content-inner-wrapper"]
            div[class="row"]
              div[class="large-12 large-centered columns text-center section-title"]
                h1
                  == yield(:title)
            div[class="row"]
              div[class="large-12 large-centered columns"]
                == yield

== render 'layouts/bottom_wrapper'

我想知道是否有办法将它们合并成一个 content_for?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 slim-lang content-for


    【解决方案1】:

    没办法。 content_for 将您的输入字符串化,因此您无法通过例如通过那个数组。您仍然可以序列化您的数据

    - content_for :title_and_class, [AppConfig.product['slogan'], 'brand'].join(';')
    - slogan, style = yield(:title_and_class).split(';')
    

    但这有点奇怪。

    【讨论】:

    • 我就是这么想的。感谢您的详尽回复,周末愉快。
    猜你喜欢
    • 2010-09-22
    • 2016-12-02
    • 2014-01-02
    • 1970-01-01
    • 1970-01-01
    • 2011-05-22
    • 2023-02-02
    • 1970-01-01
    相关资源
    最近更新 更多