![]() |
#1 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,973
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Template: Prioritizing an item in sublists
I have this template for display of two columns in Kobo subtitles and Generate Covers:
Code:
{#taglike:'sublist(list_sort($, 0, ','), 0,1,',')'} | {#anothercolumn} I see in the documentation about indexes, but that seems to be about what order it is in rather than a specific value. e.g. if 'abc, bar, foo' appears it currently shows 'abc.' I want to prioritize 'bar' so that it appears instead even though it is not first. But 'bar' may not always be the second item in the list, e.g. 'aaa, aaaaaaaah, ahhhhhhhhh!!!, bar' or 'bar, random screaming' I am thinking maybe sublists won't work for this, but something like list_re. Context: The template is for displaying fanfic information. I want it to show 'Crossovers' if that value appears in #fanficcat. ![]() Last edited by ownedbycats; 04-05-2021 at 01:58 AM. |
![]() |
![]() |
![]() |
#2 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
I would do this, assuming that there is only one priority item
Code:
{#genre:'list_contains($, ',', '^bar$', 'bar', sublist(list_sort($, 0, ','), 0, 1, ','))'} Code:
program: arguments(lst='No list argument given', items=''); r = ''; for l in items: if !r then r = str_in_list(lst, ',', l, l, '') fi rof; if !r then r = sublist(list_sort(lst, 0, ','), 0, 1, ',') fi; r Code:
{#genre:'list_priority_item($, 'Completed, Bar')'} NB 2: the loop in the stored template is a bit strange because the template language doesn't have a "break" statement. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,973
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Code:
{#fanficcat:'list_contains($, ',', '^Crossover$', 'Crossover', sublist(list_sort($, 0, ','), 0, 1, ','))'} ![]() |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Template: saving template tester when restarting Calibre | ownedbycats | Library Management | 14 | 03-29-2021 05:57 PM |
Template: Converting a search & replace into a template | ownedbycats | Library Management | 11 | 03-26-2021 04:32 AM |
Using built-in template functions in a custom template function | ilovejedd | Library Management | 4 | 01-28-2018 12:20 PM |
Lists and sublists from ePub to azw3 | draknan | Conversion | 2 | 12-25-2012 11:40 AM |