03-07-2024, 05:42 AM | #1 |
Bookish
Posts: 907
Karma: 1803094
Join Date: Jun 2011
Device: PC, t1, t2, t3, aura 2 v1, clara HD, Libra 2, Nxtpaper 11
|
Template language questions
Due to some noticed template magic in this thread , I have a question to understand some detail. I tried to locate this in the calibre user manual, but was lost.
I have a query for finding books with extra files which works well: Code:
template:"""program: if has_extra_files() then 'yes' else 'no' fi#@#:t:yes"""
Code:
template:"""program: has_extra_files()#@#:b:yes"""
|
03-07-2024, 07:31 AM | #2 | |
Grand Sorcerer
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
As for 'b', the General Program Mode documentation says:
You can't use 'b' in the first template because both 'yes' and 'no' are non-empty thus True. The check always succeeds. The second template returns the value of has_extra_files(), which is either the string '1' or the empty string. As said above, the empty string is False in the logical context so the 'b' test works. FWIW: the second template is somewhat faster. Not much because the performance difference is swamped by the time required to check the library for data files. |
|
03-07-2024, 07:56 AM | #3 | |
Bookish
Posts: 907
Karma: 1803094
Join Date: Jun 2011
Device: PC, t1, t2, t3, aura 2 v1, clara HD, Libra 2, Nxtpaper 11
|
Thanks for this information, most enlightening
Quote:
It is definitely faster on my machine, that's why I wanted to grasp the difference so I could understand what was going on. Last edited by DrChiper; 03-07-2024 at 08:11 AM. |
|
03-07-2024, 08:15 AM | #4 | |
Grand Sorcerer
Posts: 11,742
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
You can use the "Copy the current search into the boxes" in that dialog to see what a search you found elsewhere, e.g., in a forum post, is doing. For example, here is what you see with for your 2nd template search. As for why it is faster, the 2nd template has a smaller, simpler program: it doesn't use an if/then/else. For smaller libraries or fewer data files, the time to execute the 'if' statement is a larger percentage of the total. |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Template language changes | chaley | Library Management | 132 | 03-03-2024 06:34 PM |
Template Language Question | jvorzimmer | Library Management | 5 | 11-20-2021 01:26 PM |
A few questions... (template language, mainly) | Clem2605 | Library Management | 2 | 12-30-2020 03:25 AM |
Template Language | phossler | Calibre | 8 | 01-12-2016 04:37 PM |
Help with template language | Pepin33 | Calibre | 8 | 11-11-2012 08:32 AM |