« Disruptive Innovation Within the Enterprise? | Main | Robert Williams, man to watch in 2014 »

November 20, 2013

Haml's little-known list_of helper

TIL that given an Enumerable object and a block, the list_of method will iterate and yield the results of the block into sequential <li> elements.

Haml

%ul
  = list_of [1, 2, 3] do |item|
    Number #{item}

HTML

<ul>
  <li>Number 1</li>
  <li>Number 2</li>
  <li>Number 3</li>
</ul>

The list_of method also optionally takes a hash of options applied to the output li tags as attributes.


Interested in more information like this? You can download my book The Rails 4 Way at Leanpub today. Final print edition on Addison Wesley coming early next year.


If you read this far you should probably follow me on twitter:

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00e54fdca9118833019b015d916e970d

Listed below are links to weblogs that reference Haml's little-known list_of helper:

Sponsored By

Flattr

or visit my my homepage

My Companies

My Latest Books

My Book Series