Permalink
Browse files

Update the books/list view (list.tt2)

  • Loading branch information...
1 parent f811188 commit d74ee12db26123c2834f7563f13271dc192ef914 @phillipadsmith committed Aug 15, 2011
Showing with 17 additions and 1 deletion.
  1. +17 −1 root/src/books/list.tt2
@@ -13,7 +13,23 @@
<tr>
<td>[% book.title %]</td>
<td>[% book.rating %]</td>
- <td></td>
+ <td>
+ [% # NOTE: See Chapter 4 for a better way to do this! -%]
+ [% # First initialize a TT variable to hold a list. Then use a TT FOREACH -%]
+ [% # loop in 'side effect notation' to load just the last names of the -%]
+ [% # authors into the list. Note that the 'push' TT vmethod doesn't return -%]
+ [% # a value, so nothing will be printed here. But, if you have something -%]
+ [% # in TT that does return a value and you don't want it printed, you -%]
+ [% # 1) assign it to a bogus value, or -%]
+ [% # 2) use the CALL keyword to call it and discard the return value. -%]
+ [% tt_authors = [ ];
+ tt_authors.push(author.last_name) FOREACH author = book.authors %]
+ [% # Now use a TT 'virtual method' to display the author count in parens -%]
+ [% # Note the use of the TT filter "| html" to escape dangerous characters -%]
+ ([% tt_authors.size | html %])
+ [% # Use another TT vmethod to join & print the names & comma separators -%]
+ [% tt_authors.join(', ') | html %]
+ </td>
</tr>
[% END -%]
</table>

0 comments on commit d74ee12

Please sign in to comment.