|
|
#1 |
|
Junior Member
![]() Posts: 7
Karma: 10
Join Date: Mar 2025
Device: Kobo Clara BW
|
Template: Working with if-elif
Hello,
I have a custom column that shows the days spent on reading a book. I am trying to create another column that shows the text value based on the days spent. Here is the code I am using: Code:
program: p = $$#daystaken; if p < 4 then 'Fast Paced' elif ((p >= 4) && (p < 8)) then 'Medium Paced' elif p >=8 then 'Slow Paced' fi )
|
|
|
|
|
|
#2 |
|
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,366
Karma: 79528341
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
I think your issue is you forgot the # for the numbers. I made this mistaek too.
If not: What do you get if you remove line 4 (fast paced)? (You need to change the next one to use an 'if.') Does it become the right value, error, or display nothing? I troubleshoot templates this way by go line-by-line. (I think breakpoints are supposed to also do this but I've not figured out how to use them entirely.) Last edited by ownedbycats; 03-10-2025 at 12:10 PM. |
|
|
|
| Advert | |
|
|
|
|
#3 |
|
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,366
Karma: 79528341
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
You can also do this with a switch_if(), I think. I find it a bit easier to use.
Here's a similar example I use: Code:
program: cost = $$#purchasecost; switch_if( cost == 'none', '', 'kobopoints:' inlist $#admintags, '[Kobo VIP]', cost ==# '00.00', '$0.00', cost <=# '00.99', '$0.01 - $0.99', cost <=# '04.99', '$1.00 - $4.99', cost <=# '10.00', '$5.00 - $9.99', cost <=# '15.00', '$10.00 - $14.99', cost <=# '15.00', '$10.00 - $14.99', cost <=# '20.00', '$15.00 - $19.99', cost <=# '30.00', '$20.00 - $29.99', '$30.00 and up' ) Last edited by ownedbycats; 03-10-2025 at 12:06 PM. |
|
|
|
|
|
#4 |
|
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 924
Karma: 810834
Join Date: Sep 2017
Location: Buenos Aires, Argentina
Device: moon+ reader, kindle paperwhite
|
Would it be something like that?
Code:
program: p = $$#daystaken + 0; if p < 4 then 'Slow pace' elif p < 8 then 'Fast pace' else 'Medium pace' fi Last edited by dunhill; 03-10-2025 at 01:19 PM. |
|
|
|
|
|
#5 |
|
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,366
Karma: 79528341
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
|
|
|
|
| Advert | |
|
|
|
|
#6 |
|
Junior Member
![]() Posts: 7
Karma: 10
Join Date: Mar 2025
Device: Kobo Clara BW
|
Thanks very much @ownedbycats and @dunhill.
I updated the code based on your ideas. I added # in front of numbers and used only < instead of >. It is working now. Here is the working code: Code:
program: p = $$#daystaken; if p <=# 4 then 'Fast Paced' elif p<=# 8 then 'Medium Paced' elif p<=# 15 then 'Slow Paced' else 'Unknown' fi |
|
|
|
![]() |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Series template not working send to device | algernonramone | Library Management | 4 | 06-05-2024 03:46 PM |
| Cailbre copy to device save template not working | algernonramone | Calibre | 3 | 03-16-2023 05:51 PM |
| custom template suddenly stoppped working | shoelesshunter | Library Management | 5 | 08-07-2020 12:28 AM |
| Send to Device Template not working | dkperez | Library Management | 3 | 12-01-2016 09:36 PM |
| [Old Thread] Save Template not working | TGinAZ | Calibre | 7 | 01-18-2012 02:03 AM |