Sha256: a09b428ad35441832bdf53da18cd8f5924c6d255b6a45ddb8f699204e81adc21
Contents?: true
Size: 1.97 KB
Versions: 15
Compression:
Stored size: 1.97 KB
Contents
# Partials Partials allows defining templating sections in external variables, such as the `hobby_entry_partial` variable above. The greater tag allows you to instantiate those partials: * greater (>) renders the partial denotes by an expression in the current scope For instance, <ul> <li><a href="http://reddit.com/r/programming">Programming</a></li> <li><a href="http://www.music.me/">Music</a></li> </ul> will generate the hobby list with a link for each of my hobbies. As the scope inside the iteration is based on the currently iterated element, the hobby label and url are accessible inside the partial itself. # Advanced scoping example Suppose that, in the example above, you dont statically know what are the keys of an hobby hash. For instance, for each hobby you want to display an HTML table with every (key,value) pair. You could try something like this: <ul> <table> <tr> <th>key</th> <th>value</th> </tr> <tr> <td>label</td> <td>Programming</td> </tr> <tr> <td>url</td> <td>http://reddit.com/r/programming</td> </tr> </table> <table> <tr> <th>key</th> <th>value</th> </tr> <tr> <td>label</td> <td>Music</td> </tr> <tr> <td>url</td> <td>http://www.music.me/</td> </tr> </table> </ul> The `hobby_entry_table` partial above iterates the hobby hash through `self`. Following ruby's `Hash#each` The scope inside that iteration is therefore an array of two elements, accessible under `first` and `last`. Another way, that uses wlang higher-level constructions, could be as follows: <ul> <table> <tr> <td>label</td> <td>Programming</td> </tr> <tr> <td>url</td> <td>http://reddit.com/r/programming</td> </tr> </table> <table> <tr> <td>label</td> <td>Music</td> </tr> <tr> <td>url</td> <td>http://www.music.me/</td> </tr> </table> </ul>
Version data entries
15 entries across 15 versions & 1 rubygems