05-28-2011, 01:01 PM | #1 |
Junior Member
Posts: 5
Karma: 10
Join Date: May 2011
Device: ipad
|
Custom Coloring
Hi-
I'm hoping someone can help me come up with a template that does something simple, but appears to be beyond my understanding of the template language (which isn't hard). I'm trying to get the title to turn red if the tags field is empty. I've tried all sorts of variations that I can think of with the ifempty operator, but I'm not finding the right combination. Any help would be appreciated. Thanks! |
05-28-2011, 01:08 PM | #2 |
creator of calibre
Posts: 43,842
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
{tags:'test($, "red", "black")'}
|
Advert | |
|
05-28-2011, 02:09 PM | #3 |
Connoisseur
Posts: 58
Karma: 10
Join Date: Mar 2011
Device: Kindle 3 3G
|
The new coloring is really useful. Is there a possibility to color the line background instead of the text or even color the text of the whole line not only one column?
|
05-28-2011, 02:33 PM | #4 |
ZCD BombShel
Posts: 4,793
Karma: 8293322
Join Date: Jan 2009
Location: The Frozen North (aka Illinois, USA)
Device: iPad, STB Kindle Oasis
|
Well, you got further than I did, anyway, Ken. I took one look at the editor and decided my calibre could just stay one color! For the record, I AM NOT COMPLAINING!! Just observing that the feature sounds great but is apparently beyond me.
|
05-28-2011, 04:27 PM | #5 |
Grand Sorcerer
Posts: 11,733
Karma: 6690881
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
|
Advert | |
|
05-28-2011, 04:28 PM | #6 |
creator of calibre
Posts: 43,842
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
phenomshel: The next calibre release should have two modes for specifying coloring a "Basic" mode and an advanced mode (you should find the basic mode usable).
|
05-28-2011, 04:40 PM | #7 |
Connoisseur
Posts: 58
Karma: 10
Join Date: Mar 2011
Device: Kindle 3 3G
|
Too bad, I hoped a little script could manage this.
|
05-28-2011, 05:46 PM | #8 |
Groupie
Posts: 156
Karma: 354
Join Date: Mar 2009
Location: US
Device: iPad mini, iPad 2, Kindle 3
|
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!
|
05-28-2011, 06:12 PM | #9 | |
Grand Sorcerer
Posts: 11,733
Karma: 6690881
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
What you want is something like: Code:
program: test(and( test(field('tags'), '', '1'), switch(field('#read'), 'No', '1', '')), 'red', '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') 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') Last edited by chaley; 05-28-2011 at 06:27 PM. Reason: Add a third option |
|
05-28-2011, 07:34 PM | #10 |
Groupie
Posts: 156
Karma: 354
Join Date: Mar 2009
Location: US
Device: iPad mini, iPad 2, Kindle 3
|
Oh wow, perfect, thank you so much! Seeing those three models really helps me better understand how to actually use the template language - it's so helpful, I really appreciate it.
Another question for you: can you test on the ondevice field? If so, what happens if there is no device connected? Or do you first have to check to see if that field exists? |
05-28-2011, 10:40 PM | #11 |
eBook Junkie
Posts: 1,526
Karma: 1464018
Join Date: May 2010
Location: USA
Device: Kindle Fire 2020, Kindle PW2
|
If you all do not mind me asking, what reasons would you want to use the coloring, what benefit are you expecting??
|
05-29-2011, 12:15 AM | #12 |
Junior Member
Posts: 5
Karma: 10
Join Date: May 2011
Device: ipad
|
Red and Black
Thank for the quick reply... now the question is where to enter this. I thought it would go in the tags wizard in column coloring, but apparently not.
I don't remember seeing any info on the test command, but I never would have gotten there anyway Thanks again! Ken |
05-29-2011, 01:16 AM | #13 |
creator of calibre
Posts: 43,842
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Put it into one of the white boxes and change the combobox next to it to read title. You cant use the Tag Wizard for this template.
|
05-29-2011, 06:08 AM | #14 |
Connoisseur
Posts: 58
Karma: 10
Join Date: Mar 2011
Device: Kindle 3 3G
|
@nynaevelan
I use the coloring for marking 2 types of books in my bibliothek.
|
05-29-2011, 09:10 AM | #15 | |
Grand Sorcerer
Posts: 11,733
Karma: 6690881
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
However, it is clearly useful to be able to use ondevice in color templates, so I have added a new template function, ondevice(), to fetch its value. This function should appear in the next release, earlier if you run from source. The function returns 'Yes' (translated if not running in English) if a device is connected and the book is on that device. It returns the empty string if the book is not on the device or if a device is not connected. You can use the ondevice function where you would use field('ondevice') if only ondevice were a real field. You can also use it in template function mode as {:'ondevice()'} (the field name is omitted). |
|
Tags |
calibre, template |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Can custom book data be displayed in a custom column? | kiwidude | Development | 9 | 03-02-2011 05:35 AM |
Custom charge? | daoshi | iRex | 3 | 10-06-2008 06:47 PM |