Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 10-20-2016, 02:53 PM   #1
MicaOlaAdams
Member
MicaOlaAdams began at the beginning.
 
Posts: 22
Karma: 10
Join Date: Oct 2016
Device: Kobo Aura One
Problem with contains function in save template

Hi everybody,

I set the following save template
Code:
{#genre:contains(Sachbuch, {title}, {author}_{title})}
The idea is to save books with the "Sachbuch"-genre only by title and any thing else by author and title.

Now every book that has any of the following characters in its title throws an error
Code:
, { } ( )
Code:
ValueError: Failed to calculate path for save to disk. Template: {#genre:contains(Sachbuch, {title}, {authors}_{title})}
    Error: Incorrect number of arguments for function contains
I suppose this is because those characters are part of the function itself.

Any ideas how to solve this problem?
MicaOlaAdams is offline   Reply With Quote
Old 10-20-2016, 05:52 PM   #2
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,362
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Your problem is happening because you didn't respect what it says in the template language manual, "Do not use subtemplates (`{ ... }`) as function arguments." In addition, in single-function-mode spaces are significant. You should include them only where you want them in the output.

The most general way to fix this is to use general program mode. Something like
Code:
program:
	contains(
		field('#genre'),
		'Sachbuch', 
		field('title'), 
		strcat(field('authors'), '_', field('title'))
	)
chaley is offline   Reply With Quote
Advert
Old 10-21-2016, 03:36 AM   #3
MicaOlaAdams
Member
MicaOlaAdams began at the beginning.
 
Posts: 22
Karma: 10
Join Date: Oct 2016
Device: Kobo Aura One
Many thanks.

I'm still new to this whole template language thing and have overlooked this warning completely.
MicaOlaAdams is offline   Reply With Quote
Old 10-21-2016, 05:58 AM   #4
MicaOlaAdams
Member
MicaOlaAdams began at the beginning.
 
Posts: 22
Karma: 10
Join Date: Oct 2016
Device: Kobo Aura One
I read now the manual, but I still don't understand how I can include a folder structure for a save template in general program mode.

E.g. to save books from the "Sachbuch"-genre into /genre/series/title and everything else into /genre/author/title.

Maybe somebody could provide a exemplary code.
MicaOlaAdams is offline   Reply With Quote
Old 10-21-2016, 06:19 AM   #5
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,362
Karma: 8012652
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Code:
program:
	middle = contains(
		field('#genre'),
		'Sachbuch', 
		field('series'), 
		field('authors')
	);
	strcat(field('#genre'), '/', middle, '/', field('title'))
chaley is offline   Reply With Quote
Advert
Old 10-21-2016, 10:25 AM   #6
MicaOlaAdams
Member
MicaOlaAdams began at the beginning.
 
Posts: 22
Karma: 10
Join Date: Oct 2016
Device: Kobo Aura One
I've been thinking this whole thing backwards

Thanks again!
MicaOlaAdams is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use re() function in Template Program Mode? msciwoj Library Management 3 07-07-2016 03:55 PM
Save Books to Disk Template Problem Buckskin Library Management 5 11-15-2015 11:37 AM
Save template problem antoon Library Management 12 08-17-2012 12:47 PM
A little help with a save template...? Belfaborac Library Management 2 02-04-2011 09:47 PM
problem to save with customize template Roxro Library Management 4 01-22-2011 07:37 AM


All times are GMT -4. The time now is 07:13 AM.


MobileRead.com is a privately owned, operated and funded community.