Jade Style Blocks in Ruby Patterns (Haml?)

Is there a template engine in Ruby that supports something like Jade extend and block ( https://github.com/visionmedia/jade#template-inheritance )? This is an awesome feature compared to the simple :layout option supported by Haml and similars.

Any ideas on how to implement these blocks in Ruby? Maybe decrypt the Haml syntax?

+4
source share
1 answer

Yes, can you use content_for? and yield in haml for template inheritance. Example:

Base.html.haml

  % html
         = render "layouts / head"
             % body
                 .container.container-main
                     = content_for? (: page_content)?  yield (: page_content): yield

Now you can use 'page_content' from another haml =>

Derived.html.haml

  - content_for: page_content do 
         / contents

Everything contained in the content_for: block_name block is executed in the context of the corresponding result in the layout.

+1
source

All Articles