01-25-2022, 05:26 PM | #1 |
Member
Posts: 13
Karma: 10
Join Date: Jul 2013
Device: none
|
Template Function SEPARATORS - valid characters
In template functions that require a separator, what characters are valid?
I'm trying to get the first word of a field using sublist() {series:sublist(0₁1,❓)} I'd like to use a space, but it won't accept that, nor if I escape it, or use \s, put it in quotes... so - how can it be done, is there a way to separate with a space, or should I be using a different function (sublist seemed the most obvious)? |
01-25-2022, 05:30 PM | #2 |
Custom User Title
Posts: 8,758
Karma: 62032371
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Check out the template reference if you've not already.
|
Advert | |
|
01-25-2022, 05:33 PM | #3 |
Member
Posts: 13
Karma: 10
Join Date: Jul 2013
Device: none
|
I've looked through it several times, read through it and tried various searches - it never specifies valid characters for separators. It also doesn't seem to have come up in the forums before.
By the way - thanks to Ownedbycats and Capink for answering my previous question, without them I couldn't ask this next one! |
01-25-2022, 06:05 PM | #4 | ||
Grand Sorcerer
Posts: 11,768
Karma: 7029857
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Quote:
As for list separators, that is up to you. Any string can be used as a separator in the Template or General Program modes. Calibre uses both comma and ampersand, depending on the data. In some cases it uses a colon, for example in identifiers. You seem to want to split a space-separated phrase into words, which is possible in the more general modes but isn't something calibre does with its standard data types. Last edited by chaley; 01-25-2022 at 06:14 PM. Reason: missing word |
||
01-25-2022, 07:27 PM | #5 | |
Member
Posts: 13
Karma: 10
Join Date: Jul 2013
Device: none
|
Quote:
I'm not much of a programmer, I'm mostly just making semi-educated guesses based on a couple of classes I took 20 years ago (C++ & tried to self teach Obc-C) so no experience with python. When I skimmed through the docs for Program modes I got the impression that it would probably take less time for me to just manually change the text of the books that are causing me problems than it would to learn to solve this programatically. I thank everyone for their time & especially those who responded! |
|
Advert | |
|
01-25-2022, 08:20 PM | #6 | |
Grand Sorcerer
Posts: 24,906
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
Quote:
Code:
{series:sublist(0,2, )} But, as @chaley mentioned, there are three modes. I don't like the above version. I would use General Program mode: Code:
program: sublist($series, 0, 2, " ") You could do this with regex: Code:
program: re($series, "^(.*? .*?\s).*", "\1") Code:
program: re($series, "^(.*?[\s:].*?[\s:]).*", "\1") |
|
01-25-2022, 09:54 PM | #7 |
Member
Posts: 13
Karma: 10
Join Date: Jul 2013
Device: none
|
|
01-26-2022, 03:58 AM | #8 | |
Grand Sorcerer
Posts: 11,768
Karma: 7029857
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
{series:'sublist($, 0, 2,' ')'} But like @davidfor, I prefer GPM. They are easier to read and can be faster. |
|
Tags |
functions, syntax, template language, templates |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
BuiltinAdd template language function | DyckBook | Editor | 4 | 10-19-2021 04:21 PM |
Bulk metadata Search/Replace: template function question | meghane_e | Library Management | 3 | 01-24-2019 09:32 PM |
Using built-in template functions in a custom template function | ilovejedd | Library Management | 4 | 01-28-2018 12:20 PM |
Problem with contains function in save template | MicaOlaAdams | Calibre | 5 | 10-21-2016 10:25 AM |
how to use re() function in Template Program Mode? | msciwoj | Library Management | 3 | 07-07-2016 03:55 PM |