Quote:
Originally Posted by jesscat
Continuing this thread rather than starting a new one: what if you want the title to be red if (for example) tags are empty *and* the #read field is "no." I'm perplexed about how to use the template language when you want to test two different fields; I keep looking for an "and" operator, but I'm pretty certain that's not the right way to go about it!
|
There is an 'and' function. It returns a non-empty value if all its arguments are non-empty (true), otherwise empty (false).
What you want is something like:
Code:
program:
test(and(
test(field('tags'), '', '1'),
switch(field('#read'), 'No', '1', '')),
'red',
'black')
In this case the and() checks if two things are true: the tags field is empty (the test() inside the and) and the #read field is no (the switch() inside the and). The first (outermost) test checks if the and() is true, and if so returns 'red', otherwise 'black'.
There are other ways to do this. For example, you can construct a string by concatenating tags and #read, then check if it is 'no' with something like
Code:
program: switch(strcat(field('tags'), field('#read')), '^No$', 'red', 'black')
The concatenated string can be 'no' only if tags are empty and #read is no.
A third way is similar to the second, but using comparison instead of switch.
Code:
program: strcmp(strcat(field('tags'), field('#read')), 'no', 'black', 'red', 'black')