View Single Post
Old 03-08-2015, 08:21 PM   #2
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
General Program Mode is activated by the "program:" at the beginning -- it means everything afterward is a part of the program. Don't repeat that text twice, simply end all statements with a ";" and the last one will be evaluated as the template result.

and(value, value, ...)
Quote:
returns the string “1” if all values are not empty, otherwise returns the empty string. This function works well with test or first_non_empty. You can have as many values as you want.
You can use something like:

Code:
program:

# return "Yes" if #new is set to yes, else return empty.
rule1 = contains(
    field('#new'),
    'Yes',
    'Yes',
    ''
);

# Return the list of authors that are in both
# the authors field and a custom list.
# Returns empty if there are no matches.
list_of_authors = 'author1, author2, author3';
rule2 = list_intersection(
    list_of_authors,
    field('authors'),
    '&'
);

# The "and" function tests if both rules returned
# a value (and are therefore true).
test(
    and(rule1, rule2),
    'icon-if-true',
    ''
);
I have no idea at what point calibre might decide it is too many authors and crash or something, but I do know it will indeed require you embed the authors manually into the template -- since templates cannot read from the database, and they only know the metadata from the current book.

TBH, this should probably be a custom python script run through calibre-debug.exe which writes the appropriate values to a custom column after evaluating the data. That would be a lot more usable.
eschwartz is offline   Reply With Quote