04-29-2014, 04:50 AM | #1 |
Enthusiast
Posts: 47
Karma: 10
Join Date: May 2011
Device: Samsung Galaxy 3 8.0 /Samsung Galaxy S5 / PC
|
Save Template Help
So I'm trying to get Calibre to use the first letter of a series name and if not that, the title of the book, only the help docs are archaic to understand and don't provide enough examples.
I found this: {#series:'ifempty($, field('#genre'))'} But I'm not using metadata at all, just 'series' or if empty 'title' Which get's me: {series:'ifempty($, field("title"))'}/{series} [{series_index}] - {title} ({author}) BUT... where do I put in the '.1' for only the series or title letter. |
04-29-2014, 04:10 PM | #2 |
Ex-Helpdesk Junkie
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
series and title are types of metadata...
I am not entirely clear on what you want to see. Can you give a sample book and how you wish to see it saved? Also, if you post your template question here: https://www.mobileread.com/forums/sho...d.php?t=100949 on the dedicated templates thread, more people can see and hopefully answer. |
05-05-2014, 04:06 AM | #3 |
Enthusiast
Posts: 47
Karma: 10
Join Date: May 2011
Device: Samsung Galaxy 3 8.0 /Samsung Galaxy S5 / PC
|
I thought that topic was only for POSTING templates not asking about help. Thus the new topic. Maybe this can be merged?
As for what I want, let's take two imaginary books: The Caterpillar's Day [Happy Bugs #1] by Some Person There is A Cat Here by That Peep I basically wanted them sorted into folder's like this: H/Happy Bugs [1] - The Caterpillar's Day (Some Person) T/There is A Cat Here (That Peep) Basically the first letter of the series and if no series then the title becomes the folder, then they are placed in their own folder by series/title I can get it to do the LETTER for a folder, but I don't know how to set it to fall back on the title if there is no series. |
05-05-2014, 11:28 AM | #4 |
Ex-Helpdesk Junkie
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
No big deal, it works just fine here too. But the other thread is handy since I and several other template gurus are subscribed already, so we are sure to see questions.
To answer your question, template programming mode (that's where we get to use functions) looks like this: Code:
{fieldname:formatting:'function(arguments)'|prefix|suffix} ".1" is formatting, so you will want to use Code:
{series:.1:'ifempty($, field("title"))'}/{series}{series_index:| [|] - }{title} ({authors}) Last edited by eschwartz; 05-19-2014 at 11:05 AM. Reason: template typo -- thanks, chaley! |
05-19-2014, 08:39 AM | #5 |
Enthusiast
Posts: 47
Karma: 10
Join Date: May 2011
Device: Samsung Galaxy 3 8.0 /Samsung Galaxy S5 / PC
|
OK thanks I'll bookmark this thread for the section breakdown. I don't remember seeing that in the template help, or if it WAS there, it was more confusing than this example.
However when I try to use the code I get: calibre, version 1.37.0 ERROR: Invalid template: The template {series:.1:'ifempty($, field("title"))'}/{series}{series_index| [|] - }{title} ({authors}) is invalid: string indices must be integers, not unicode Last edited by Maverynthia; 05-19-2014 at 08:42 AM. |
05-19-2014, 08:44 AM | #6 |
Ex-Helpdesk Junkie
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
You're Welcome.
The template help said this in a less straightforward way. I may need to fix that. |
05-19-2014, 10:34 AM | #7 | |
Grand Sorcerer
Posts: 11,738
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
{series:.1:'ifempty($, field("title"))'}/{series}{series_index:| [|] - }{title} ({authors}) |
|
05-19-2014, 10:51 AM | #8 |
Ex-Helpdesk Junkie
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Thanks chaley! I made a typo.
Fixed in my post, too. I even added an explanation -- is it good? Last edited by eschwartz; 05-19-2014 at 11:07 AM. |
05-19-2014, 11:50 AM | #9 | |
Grand Sorcerer
Posts: 11,738
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Easy to do.
Quote:
FWIW: here is an extended BNF-like grammar for templates. Text in quotes represent tokens. The square brackets indicate what is between them is optional. I didn't bother with the grammar for the functions. The two variants could be easily expressed in one grammar but I chose not to introduce the or (|) operator. Code:
"{" [ "field name" ] [ [ ":" [ "formatting" ] ] [ ":" "single Function" ] [ "|" [ "prefix" ] "|" [ "suffix" ] ] ] "}" or "{" [ "field name" ] [ [ ":" [ "formatting" ] ] [ ":'" "Template Program" "'" ] [ "|" [ "prefix" ] "|" [ "suffix" ] ] ] "}"
Last edited by chaley; 05-19-2014 at 12:39 PM. Reason: Fixed grammar. See next post for details. |
|
05-19-2014, 12:20 PM | #10 |
Ex-Helpdesk Junkie
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Thanks for the mention of BNF! I've been learning everything myself as I come across stuff -- I learn in my spare time, this isn't part of my curriculum, yet -- so I appreciate any time someone mentions anything I haven't come across yet. (I was wondering a bit what some description were that turns out to be BNF.)
According to Kovid's docs (and thus my understanding), Code:
{authors:uppercase()|prefix|suffix} Code:
{authors:uppercase():|prefix|suffix} I'd test it out myself but I typed this on my Kindle Touch. Last edited by eschwartz; 05-19-2014 at 12:23 PM. |
05-19-2014, 12:37 PM | #11 | |
Grand Sorcerer
Posts: 11,738
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
It should be Code:
"{" [ "field name" ] [ [ ":" [ "formatting" ] ] [ ":" "single Function" ] [ "|" [ "prefix" ] "|" [ "suffix" ] ] ] "}" or "{" [ "field name" ] [ [ ":" [ "formatting" ] ] [ ":'" "Template Program" "'" ] [ "|" [ "prefix" ] "|" [ "suffix" ] ] ] "}" |
|
Tags |
sort by letter, templates |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Please help on a Save to Disk template | Dammie | Library Management | 15 | 12-16-2013 09:51 AM |
Save Template question | ltwally | Library Management | 4 | 04-11-2013 06:15 PM |
Need help on a Save to Disk template | fidvo | Library Management | 2 | 08-12-2012 03:34 PM |
A little help with a save template...? | Belfaborac | Library Management | 2 | 02-04-2011 09:47 PM |
save to disk template | speakingtohe | Calibre | 9 | 05-29-2010 06:02 AM |