Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 04-07-2024, 01:59 PM   #1
flasunco
Junior Member
flasunco began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Apr 2024
Device: Kindle Paperwhite
Template language functions not being evaluated

Hey all,

I have the problem that no functions used in a template are evaluated (or parsed). Meaning, the function call itself will be part of the output.

I first tried to get the pubdate year, but now noticed that nothing seems to work (see the capitalize call).

Template:
Code:
{author_sort}/
{series:||{series_index:| #|} - }
{title} ({pubdate})/
{authors} - 
{series:||{series_index:| #|} - }
{title} 

(format_date_field('pubdate', 'yyyy'))
format_date(field('pubdate'), 'yyyy')
capitalize('asdf')

Output:
Code:
Sands, Philippe/ East West Street: On the Origins of "Genocide" and "Crimes Against Humanity" (Apr 2016)/ Philippe Sands - East West Street: On the Origins of "Genocide" and "Crimes Against Humanity" (format_date_field('pubdate', 'yyyy')) format_date(field('pubdate'), 'yyyy') capitalize('asdf')
Any help would be appreciated.
flasunco is offline   Reply With Quote
Old 04-07-2024, 03:41 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: 11,743
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by flasunco View Post
Hey all,

I have the problem that no functions used in a template are evaluated (or parsed). Meaning, the function call itself will be part of the output.

I first tried to get the pubdate year, but now noticed that nothing seems to work (see the capitalize call).

Template:
Code:
{author_sort}/
{series:||{series_index:| #|} - }
{title} ({pubdate})/
{authors} - 
{series:||{series_index:| #|} - }
{title} 

(format_date_field('pubdate', 'yyyy'))
format_date(field('pubdate'), 'yyyy')
capitalize('asdf')

Output:
Code:
Sands, Philippe/ East West Street: On the Origins of "Genocide" and "Crimes Against Humanity" (Apr 2016)/ Philippe Sands - East West Street: On the Origins of "Genocide" and "Crimes Against Humanity" (format_date_field('pubdate', 'yyyy')) format_date(field('pubdate'), 'yyyy') capitalize('asdf')
Any help would be appreciated.
The bits in bold are not valid expressions in any form of the template language. In addition, there is no 'format_date_field' function. The template expressions before the bold bits are working, as shown by your output. I suggest you look at the template language manual.

I suspect that you want this, using Single Function Mode:
Code:
{author_sort}/
{series:||{series_index:| #|} - }
{title} ({pubdate:format_date('yyyy')})/
{authors} - 
{series:||{series_index:| #|} - }
{title}
Do note that if you are using that template as a file name template, it can generate very long names. These will be shortened by calibre to fit within the 255 character file name limit. The results of the shortening process can appear to be random, even though they aren't.
chaley is offline   Reply With Quote
Old 04-08-2024, 08:03 AM   #3
flasunco
Junior Member
flasunco began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Apr 2024
Device: Kindle Paperwhite
Thank you very much for the help. Seems I must have missed the different modes when using the functions.

One problem left: using
Code:
({pubdate:format_date('yyyy')})
the year is output as a string including the apostrophes:
Code:
('2016')
To get rid of the apostrophes, I've tried format_number(), without success though.

Thanks in advance.
flasunco is offline   Reply With Quote
Old 04-08-2024, 08:08 AM   #4
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: 11,743
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by flasunco View Post
Thank you very much for the help. Seems I must have missed the different modes when using the functions.

One problem left: using
Code:
({pubdate:format_date('yyyy')})
the year is output as a string including the apostrophes:
Code:
('2016')
To get rid of the apostrophes, I've tried format_number(), without success though.

Thanks in advance.
Just remove the apostrophes in the format_date() call.
chaley is offline   Reply With Quote
Old 04-08-2024, 08:10 AM   #5
flasunco
Junior Member
flasunco began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Apr 2024
Device: Kindle Paperwhite
Well now I feel dumb. Kinda confused how that parameter doesn't have to be a string, but I'm happy with the result.

Thank you.
flasunco is offline   Reply With Quote
Old 04-08-2024, 08:14 AM   #6
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: 11,743
Karma: 6997045
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by flasunco View Post
Well now I feel dumb. Kinda confused how that parameter doesn't have to be a string, but I'm happy with the result.

Thank you.
As said in the template language manual in the Single Function Mode section:
Quote:
Important: If you have programming experience, please note that the syntax in Single Function Mode is not what you expect. Strings are not quoted and spaces are significant. All arguments are considered to be constants; there are no expressions.
And you are welcome.
chaley is offline   Reply With Quote
Reply

Tags
template language


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Template functions: where to find them? Terisa de morgan Library Management 1 09-03-2023 07:05 PM
python templates (was possible template functions) chaley Development 66 10-24-2022 12:34 PM
A little help with template functions in a composite column, please! mopkin Library Management 2 11-05-2019 11:07 PM
Using built-in template functions in a custom template function ilovejedd Library Management 4 01-28-2018 12:20 PM
template: if one of the tag is something... maybe contains or in_list functions fxp33 Calibre 4 07-19-2014 05:18 AM


All times are GMT -4. The time now is 07:12 PM.


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