Call Montréal, Canada 524-949-6869

Blog

Thursday, January 13, 2011

Capture HAML to yield in a layout

Rails has the content_for method which allows you to yield content into a layout later in the rendering phase of a view. Often I need the same functionality when using StaticMatic. Since I'm using Haml this is easier to do.

# page.haml
- @javascript = capture_haml do 
 alert("hello");

# layout.haml
:javascript
  = @javascript

Developing Ruby on Rails applications and Radiant-based Content Management Systems in Montréal. Contact Firsthand.