How to structure a layout template in Haml

前端 未结 2 1681
小蘑菇
小蘑菇 2021-01-31 11:29

I have a web page that uses Haml for layouts. \"layout.haml\" is a separate layout file which is used when rendering any actual Haml page.

layout.haml looks something l

2条回答
  •  温柔的废话
    2021-01-31 12:08

    This solution is for Ruby on Rails only:

    You can use yield(:location) and the content_for(:location) methods. "Using the content_for Method" has more information.

    layout.haml:

    !!!
    %html
      %head
        %title= yield(:title)
        = yield(:head)
      %body
        = yield
    

    view.haml:

    - content_for(:title, 'My title')
    - content_for(:head) do
      = javascript_include_tag :foo
    
    %h1 My view!
    

提交回复
热议问题