![]() |
#1 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,909
Karma: 74203799
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Template: Strcat matching
Currently, I have a column icon template like this:
Code:
program: f = field('#taglike'); strcat ( contains(f, "^foobar|foo bar$", 'foobar.png:', ''), contains(f, "foo", 'foo.png:', ''), contains(f, "bar", 'bar.png:', ''), contains(f, "test", 'test.png:', ''), ) However, how would I display an icon if the values do not match any existing ones? e.g.: Value: Unknown Results: Unknown.png Value: Unknown, Undefined Results: Unknown.png Value: Unknown, foobar Results: foobar.png ![]() |
![]() |
![]() |
![]() |
#2 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,194
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
does the below template do what you want?
Code:
program: f = field('#taglike'); icons = ''; sep = ':'; for keyword in 'foo,bar,test': val = contains(f, keyword, strcat(keyword, '.png'), ''); if val then icons = list_union(icons, val, sep) fi rof; ifempty(icons, 'unknown.png') Last edited by capink; 03-20-2021 at 06:10 AM. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,909
Karma: 74203799
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Not quite though I will save that if it comes in useful for something else.
![]() Code:
contains(f, "^Some Movie|Some Other Movie$", 'Film.png:', ''), contains(f, "One Entry of a Game Series", 'iconforseries.png:', ''), |
![]() |
![]() |
![]() |
#4 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,194
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Code:
program: f = field('#taglike'); icons = ''; sep = ':'; icon_expression = 'film.png=^Some Movie|Some Other Movie$,iconforseries.png=One Entry of a Game Series'; for item in icon_expression: icon = re(item, '(.+)=(.+)', '\1'); expression = re(item, '(.+)=(.+)', '\2'); val = contains(f, expression, icon, ''); if val then icons = list_union(icons, val, sep) fi rof; ifempty(icons, 'unknown.png') |
![]() |
![]() |
![]() |
#5 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,909
Karma: 74203799
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
I will try that.
Another thing I thought of: perhaps I could change my existing rule to a non-composed rule (which will stop other rules after it) and make a second rule saying "if field is populated, put unknown.png." ![]() |
![]() |
![]() |
Advert | |
|
![]() |
#6 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,410
Karma: 8012664
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Regarding your original question, a small change to @capink's suggestion might be easier for you to use. Something like Code:
if 'Some Movie|Some Other Movie' in f then icons = list_union(icons, 'film.png', sep) fi; if 'One Entry of a Game Series' in f then icons = list_union(icons, 'iconforseries.png', sep) fi; # and on and on ifempty(icons, 'unknown.png') |
|
![]() |
![]() |
![]() |
#7 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,410
Karma: 8012664
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
for item in icon_expression: list_split(item, '=', 'part'); if part_1 in f then icons = list_union(icons, part_0, sep) fi rof; |
|
![]() |
![]() |
![]() |
#8 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,909
Karma: 74203799
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Thank you
![]() |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
"Normal" template inside GPM template | ownedbycats | Library Management | 20 | 12-02-2020 09:40 PM |
Using built-in template functions in a custom template function | ilovejedd | Library Management | 4 | 01-28-2018 12:20 PM |
Ungreedy matching in S&R | BobC | Editor | 4 | 01-18-2014 01:31 PM |
Better matching/scanning | lbutlr | Calibre | 3 | 08-04-2010 03:44 PM |
Matching Light for Kobo | dixieknits | Kobo Reader | 2 | 07-19-2010 02:50 AM |