![]() |
#1 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,952
Karma: 74999999
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Template: unexpected result with gpm
I was modifying one of my templates and although it's valid I got a result I did not expect.
Code:
program: k = field('#kobocoll'); if check_yes_no('#onkobo', 0, 1, 0) then 'sync.png' else if check_yes_no('#onkobo', 0, 0, 1) then if list_contains(k, ',', '^Kobo Store$', '1', '') then 'drm-locked.png' fi; if list_contains(k, ',', '^Send to Device$', '1', '') then 'sync.png' else 'reader.png' fi fi fi Instead I got reader.png I put it in template tester and got the same result so it's not something else accidentally overriding the icon. I tried removing the ^ and $ in case it was a matching issue but that did not fix it. What mistake did I make? ![]() Last edited by ownedbycats; 03-15-2021 at 05:40 PM. |
![]() |
![]() |
![]() |
#2 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,440
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
The problem is that the ifs, thens, and elses don't connect the way you want. In particular you need to be careful about the difference between "else if" and "elif". The first one, "else if", introduces a new statement block that requires more indented 'fi's that match the correct 'if'. The second, "elif", matches the nearest "if" statement, making placement of 'fi's easier (for me at least).
Another problem is that an "else" clause attaches to the nearest "if". Because of that, your template will return 'reader.png' if k does not contain '^Send to Device$' even if it contains '^Kobo Store$'. Here is my guess for what you want: Code:
program: k = field('#kobocoll'); if check_yes_no('#onkobo', 0, 1, 0) then 'sync.png' elif check_yes_no('#onkobo', 0, 0, 1) then if list_contains(k, ',', '^Kobo Store$', '1', '') then 'drm-locked.png' elif list_contains(k, ',', '^Send to Device$', '1', '') then 'sync.png' else 'reader.png' fi fi Question: is #kobocoll tags-like? If not then you can use Code:
if k == 'Kobo Store' then |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,952
Karma: 74999999
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
The code you gave worked
![]() #kobocoll is taglike so I'll try that other one too Last edited by ownedbycats; 03-15-2021 at 07:08 PM. |
![]() |
![]() |
![]() |
#4 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,440
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
If #kobocoll is tags-like then '==' won't do anything good if there is more than one value in the list.
The 'in' comparison operator will work on tags-like columns as long as the searched value cannot appear more than once. For example, consider the expression Code:
if 'history' in tags then The 'in' operator is faster than list_contains(), so it is worth using as long as there aren't multiple super-strings of the search expression. |
![]() |
![]() |
![]() |
#5 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,952
Karma: 74999999
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
The values in my template don't really have any overlap so I will try that
Nice cat in your avatar ![]() |
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,440
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
![]() ![]() We "rescued" her at 6 weeks old. She was feral and she still exhibits a lot of feral behavior. For example, if I approach her then she will bare her teeth and hiss, which is what she is doing in the photo. She is deadly serious; I have the bite and claw scars to prove it. I now use a pair of arm-length leather welders gloves when I need to catch her to take her to the vet. However, if I am sitting minding my own business then she often approaches me to climb in my lap, purr softly (she has almost no voice), and "nose" my arm. At this point I can pick her up, rub her belly, and do other indignities. However, the rule is I can't directly look at her face. She gets very nervous when that happens. |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
"Normal" template inside GPM template | ownedbycats | Library Management | 20 | 12-02-2020 09:40 PM |
Well. That's unexpected. | skb | Writers' Corner | 5 | 05-06-2019 10:38 PM |
Using built-in template functions in a custom template function | ilovejedd | Library Management | 4 | 01-28-2018 12:20 PM |
Issue with Send to Device template | BookJunkieLI | Library Management | 5 | 02-14-2014 01:16 AM |
[issue] attempting to download covers can result in exception | asxpwpeukrun | Calibre | 2 | 07-01-2010 05:54 PM |