06-04-2011, 09:22 AM | #61 |
Groupie
Posts: 156
Karma: 354
Join Date: Mar 2009
Location: US
Device: iPad mini, iPad 2, Kindle 3
|
Is it possible to construct more complex if-else statements in the template language? Like - if #unread and ondevice() then title red; elseif #unread and not ondevice() then green, else black? Would switch work - or does switch have to operate on a field?
I can't figure out how to make this work with the template language if-else-then operators (contains, ifempty, test...); they all seem to allow for only one condition. (I guess this kind of relates to the comment a few pages back trying to set two rules for one column...) One other thing: I did appreciate having the link to the tutorial on the template language; might there be any way to put that back in the "advanced" rule section? (Easier than having to go look for it when I find myself needing it...) |
06-04-2011, 09:24 AM | #62 | |
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
The bottom line is that because the column does not have fixed content, you will need to match using regular expressions. What those expressions are will depend on what the column can contain. |
|
Advert | |
|
06-04-2011, 09:38 AM | #63 |
Addict
Posts: 272
Karma: 1050426
Join Date: Feb 2010
Location: California
Device: iPad Mini w/Retina, Kindle 3, Kindle Fire HDX 8.9, & Asus Transformer
|
It looks like 95=1/30/2011 or 95=4/9/2011
Reading: 33% Last edited by beckywc; 06-04-2011 at 09:40 AM. |
06-04-2011, 09:57 AM | #64 | ||
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Now to the template, which is how I would do this. Use the 'and' function to combine the terms. If you think Code:
if X and Y then Z else Q Code:
test(and(X, Y), Z, Q) Code:
if X and Y then Z1 elseif X and not Y then Z2 else Z3 Code:
first_non_empty(test(and(X, Y), Z, ''), test(and(X, not(Y)), Z2, ''), Z3) Code:
program: first_non_empty( test(and( ondevice(), switch(field('#mybool'), 'Yes', '1', '')), 'red', ''), test(and( test(ondevice(), '', '1'), switch(field('#mybool'), 'Yes', '1', '')), 'green', ''), 'black') Quote:
|
||
06-04-2011, 10:03 AM | #65 |
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Make three rules.
For the first rule, the condition is "#column matches pattern ^95=" For the second rule, the condition is "#column matches pattern ^Reading: For the third rule, the condition is "#column has Not Read" All three rules will color #column with the color of your choice. |
Advert | |
|
06-04-2011, 10:21 AM | #66 |
Addict
Posts: 272
Karma: 1050426
Join Date: Feb 2010
Location: California
Device: iPad Mini w/Retina, Kindle 3, Kindle Fire HDX 8.9, & Asus Transformer
|
Thanks Chaley,
I was able to get all but the 95 to work. |
06-04-2011, 10:25 AM | #67 |
Grand Sorcerer
Posts: 11,741
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
My guess is that there is a space somewhere that isn't in what you typed for me. Try changing the condition, removing the initial ^ character. If that doesn't work, put a space before the equals. If that doesn't work, then try the single character =.
|
06-04-2011, 10:41 AM | #68 |
Addict
Posts: 272
Karma: 1050426
Join Date: Feb 2010
Location: California
Device: iPad Mini w/Retina, Kindle 3, Kindle Fire HDX 8.9, & Asus Transformer
|
I just did this:
#pct_read is not and left the value blank and the date changed color. |
06-04-2011, 11:14 AM | #69 | |
Groupie
Posts: 156
Karma: 354
Join Date: Mar 2009
Location: US
Device: iPad mini, iPad 2, Kindle 3
|
Quote:
So thanks for this - it works perfectly and I can tweak things how I want. When "not" is restored I'll give that a try just to see how it works, but the test function gets by that very nicely. Thank you! |
|
06-04-2011, 11:48 AM | #70 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
|
06-08-2011, 04:52 PM | #71 |
Addict
Posts: 352
Karma: 103850
Join Date: Apr 2011
Device: Kindle NT
|
This is simple, but I just don't know how to work with columns Yes/No. I have custom column #read. How to make it color title in green if the book is read (Y)?
I would also like to color in read books which metadata is missing. Fields comments (false), and custom column #tagsshelf (false, it is combined column of tags and shelves), cover (false). If any of these are missing it should be in red. I guess those two can overlap, so maybe for the second it could color format column or author column. Is there any other useful material, other than this http://manual.calibre-ebook.com/template_lang.html ? I'd really like to learn template language, but I need to begin from complete basics. TIA |
06-08-2011, 05:05 PM | #72 | |
Well trained by Cats
Posts: 29,801
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
Add a rule button Set the color of Column <pick> to <pick color> Only if the conditions are satisfied If the <pick column to test> <pick type of test (depends on column type) At the bottom you can click and add a second condition that must be met... OK In your case, you probably want 2 separate rules Just return to the Tool and ADD another rule. True and Yes are the same for a Yes/No column |
|
06-08-2011, 05:20 PM | #73 |
Addict
Posts: 352
Karma: 103850
Join Date: Apr 2011
Device: Kindle NT
|
I haven't updated calibre yet, maybe the tool is new as I don't see anything like that. Although I succeeded with program:test(field('#tagsshelf'), '', 'red').
Will try the Tool for the first question, since I managed the second one. Thanks for such a quick answer Last edited by Noughty; 06-08-2011 at 05:35 PM. |
06-08-2011, 05:58 PM | #74 | |
Well trained by Cats
Posts: 29,801
Karma: 54830978
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
|
|
06-09-2011, 05:44 AM | #75 |
Addict
Posts: 352
Karma: 103850
Join Date: Apr 2011
Device: Kindle NT
|
Thanks, updated and used it. Great tool. Very useful for those who have trouble with template languages (like me )
Ok, after update other rules got messed up or they weren't working even before (although it looked ok). With columns you can use tool, but I need rules for comments and covers. I have program:test(field('comments'), 'black', 'red') (as I understand first color is for true, second for false, how to make it to do something only then it is false? If I remove black, it colors everything in red) With tool I made rule to color red if there is nothing in the column. So it checks comments and tagsshelf. I also want to add covers: and another rule program:test(field('cover'), '', 'red') But it isn't working. I need it to color in red if there is no cover, comments or tagsshelf (tags separated comma, combined column). If any is missing it should color. TIA Last edited by Noughty; 06-09-2011 at 07:38 AM. Reason: question |
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 |