diff --git a/src/calibre/constants.py b/src/calibre/constants.py index 91c114359c..4c372c63a5 100644 --- a/src/calibre/constants.py +++ b/src/calibre/constants.py @@ -2,7 +2,7 @@ __license__ = 'GPL v3' __copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net' __docformat__ = 'restructuredtext en' __appname__ = 'calibre' -__version__ = '0.7.901' +__version__ = '0.7.902' __author__ = "Kovid Goyal " import re diff --git a/src/calibre/manual/template_lang.rst b/src/calibre/manual/template_lang.rst index 541b5da138..59e5c1da4c 100644 --- a/src/calibre/manual/template_lang.rst +++ b/src/calibre/manual/template_lang.rst @@ -19,7 +19,7 @@ For the book "The Foundation" by "Isaac Asimov" it will become:: You can use all the various metadata fields available in calibre in a template, including the custom columns you have created yourself. To find out the template name for a column sinply hover your mouse over the column header. Names for custom fields (columns you have created yourself) are always prefixed by an #. For series type fields, there is always an additional field named ``series_index`` that becomes the series index for that series. So if you have a custom series field named #myseries, there will also be a field named #myseries_index. In addition to the column based fields, you also can use:: - {formats} - A list of formats available in the |app| library for a book + {formats} - A list of formats available in the calibre library for a book {isbn} - The ISBN number of the book If a particular book does not have a particular piece of metadata, the field in the template is automatically removed for that book. So for example:: @@ -40,7 +40,20 @@ and if a book does not have a series:: Advanced formatting ---------------------- -You can do more than just simple substitution with the templates. You can also control how the substituted data is formatted. For instance, suppose you wanted to ensure that the series_index is always formatted as three digits with leading zeros. This would do the trick:: +You can do more than just simple substitution with the templates. You can also conditionally include text and control how the substituted data is formatted. + +Regarding conditionally including text: there are cases where you might want to have text appear in the output only if a field is not empty. A common case is series and series_index, where you want either nothing or the two values with a hyphen between them. Calibre handles this case using a special field syntax. +For example, assume you want to use the template + + {series} - {series_index} - {title} + +Unfortunately, if the book has no series, the answer will be '- - title'. Many people would rather it be simply 'title', without the hyphens. To do this, use the extended syntax {some_text|field|other_text}. When you use this syntax, if field has the value SERIES then the result will be some_textSERIESother_text. If field has no value, then the result will be the empty string (nothing). Using this syntax, we can solve the above series problem with the template:: + + {series}{ - |series_index| - }{title} + +The hyphens will be included only if the book has a series index. Note: you must either use no | characters or both of them. Using one, such as in {field| - }, is not allowed. It is OK to not provide any text for one side or the other, such as in {\|series\| - }. Using {\|title\|} is the same as using {title}. + +Now to formatting. Suppose you wanted to ensure that the series_index is always formatted as three digits with leading zeros. This would do the trick:: {series_index:0>3s} - Three digits with leading zeros