Click here to skip to this page's main content. Site Index

 Hello!   The State of California is participating in our In-Library lending program. Browse the growing lending library of over 200,000 eBooks!

Macro to display cover image

This doc was last edited by Anand Chitipothu December 1, 2009.

plugin upstream
Templates in the website are disabled now. Editing them will not have any effect on the live website.
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
$def with(book, size="M")

$ title = book.title_prefix + " " + book.title

$ olid = book.key.split("/")[2]

$code:
    def aname(a):
        if isinstance(a, basestring):
            return a
        else:
            return a.name or ""

$if size == "M":
    <div class="cover-wrapper">
        <img src="http://covers.openlibrary.org/b/olid/$olid-M.jpg?default=false" onerror="\$(this).hide(); \$('#default-cover-$olid').show();" width="173"/>
        <div class="default-cover-$size.lower()" id="default-cover-$olid" style="display: none;">
            <div id="book-title">
                $ author_names = ", ".join(aname(a) for a in book.authors) or book.get('by_statement','')
                $:macros.TruncateString(title, 70)
                <div id="author-names">$author_names</div>
            </div>
        </div>
    </div>
$else:
    <img src="http://covers.openlibrary.org/b/olid/$olid-S.jpg?default=http://openlibrary.org/static/images/blank.book.png" height="58"/>