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 Today, 01:01 PM   #181
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,510
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
18 Sept 2025 (in calibre source)
  • A new function 'f_string()' that formats text similarly to python's 'f' strings.

    f_string(string) -- interpret string similar to how python interprets f strings. The indended use is to simplify long sequences of str & str or strcat(a,b,c) expressions.

    Text between braces ({ and }) must be General Program Mode template expressions. The expressions, which can be expression lists, are evaluated in the current context (current book and local variables). Text not between braces is passed through unchanged.

    Examples:
    • f_string('Here is the title: {$title}') - returns the string with {$title} replaced with the title of the current book. For example, if the book's title is 20,000 Leagues Under the Sea then the f_string() returns "Here is the title: 20,000 Leagues Under the Sea".
    • Assuming the current date is 18 Sept 2025, this f_string()
      Code:
      f_string("Today's date: the {d = today(); format_date(d, 'd')} of {format_date(d, 'MMMM')}, {format_date(d, 'yyyy')}")
      returns the string Today's date: the 18 of September, 2025. Note the expression list (an assignment then an if statement) used in the first { ... } group to assign today's date to a local variable.
    • If the book is book #3 in a series named Foo that has 5 books then this template
      Code:
      program:
          if $series then
              series_count = book_count('series:"""=' & $series & '"""', 0);
              return f_string("{$series}, book {$series_index} of {series_count}")
          fi;
          return 'This book is not in a series'
      returns "Foo, book 3 of 5".
chaley is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A few questions... (template language, mainly) Clem2605 Library Management 2 12-30-2020 03:25 AM
Template Language phossler Calibre 8 01-12-2016 04:37 PM
Help needed with template language Mamaijee Devices 12 02-19-2013 01:52 AM
Help with template language Pepin33 Calibre 8 11-11-2012 08:32 AM
Template language question BookJunkieLI Library Management 7 02-02-2012 06:55 PM


All times are GMT -4. The time now is 10:15 PM.


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