I appreciate your trying to solve the problem from the docs.
Try this:
Code:
program:
t = field('tags');
strcat
(
contains(t, "tag1", 'letter-a-icon.png:', ''),
contains(t, "tag2", 'letter-c-icon.png:', ''),
contains(t, "tag3", 'letter-b-icon.png:', ''),
contains(t, "tag4", 'letter-b-icon.png:', ''),
contains(t, "tag5", 'letter-d-icon.png:', ''),
contains(t, "tag6", 'letter-x-icon.png:', ''),
contains(t, "tag7", 'letter-i-icon.png:', ''),
contains(t, "tag8", 'letter-c-icon.png:', ''),
contains(t, "tag9", 'letter-p-icon.png:', ''),
contains(t, "tag10", 'letter-p-icon.png:', ''),
contains(t, "tag11", 'letter-r-icon.png:', ''),
contains(t, "tag12", 'letter-s-icon.png:', ''),
contains(t, "tag13", 'letter-s-icon.png:', ''),
contains(t, "tag14", 'letter-x-icon.png:', ''),
contains(t, "tag15", 'letter-w-icon.png:', '')
)
I added a colon at the end of each icon name and changed "first_non_empty" to "strcat" (string concatenate). Calibre uses a colon to separate icon file names. The template produces a list of image names, so calibre will display each icon in the list. I changed all the "field('tags') to 't' for performance.
For the purists out there, calibre ignores empty icon names. For example, :::foo.png::: will produce only foo.png. This means we don't need to deal with the "second time" or "last time" problem, trying to account for hanging colons.
And just for fun, here is a way to supply a single different icon if two tags are present otherwise supply different icons:
Code:
program:
t = field('tags');
has_foo = contains(t, 'foo', '1', '');
has_bar = contains(t, 'bar', '1', '');
first_non_empty
(
test(and(has_foo, has_bar), 'foo_and_bar.png', ''),
test(has_foo, 'foo.png', ''),
test(has_bar, 'bar.png', '')
)