Display functions
Display functions turn a value into text for the page. They are plain calls, with the value first:
{ currency(album.price) }prints$28.00.{ pluralize(albums.length, 'album') }prints the count with the word:1 album,3 albums.{ date(album.released, 'long') }printsApril 12, 2019;'short'and'medium'are the other presets.{ truncate(text, 60) }cuts text to 60 characters, ending in….{ raw(album.notes) }renders HTML instead of escaping it, through a sanitizer that drops scripts, styles and event attributes.
Calls nest, so { truncate(strip_html(album.notes), 60) } drops the tags first, then shortens. There are more: number_with_delimiter, percentage, capitalize, time, timeago and others.
Your own functions work the same way. Register them under formatters in app.js and call them by name in any template. Keep them pure: same input, same output.
formatters: {
duration: (seconds) => `${Math.round(seconds / 60)} min`,
},
Your turn
Shop.pzl: show each card's price withcurrency(album.price)in a<span class="price">above the button.Playlist.pzl: the count says "1 albums". Usepluralize(albums.length, 'album'). Then replace the artist under each title with the notes, tags removed and cut to 60 characters.Album.pzl: print the release date withdate(album.released, 'long'), and render the notes withraw(). They show their<em>tags as text until you do.app.js: registerduration, then use it inAlbum.pzlto print the album's length after the track count:{ pluralize(tracks.length, 'track') } · { duration(totalSeconds) }.data()already adds uptotalSeconds.