|
![]() |
|
Thread Tools | Search this Thread |
![]() |
#1 |
Junior Member
![]() Posts: 2
Karma: 10
Join Date: Nov 2019
Device: none
|
A little help with template functions in a composite column, please!
![]() I am not a programmer, and I am stuck with the template in a custom column I am trying to create. I was hoping, someone here could help me. I have 2 custom columns which I use as source of data for the third column. Column_1 is looking for PDFs in book formats, and when PDF is not present, returns N/A. Here's the expression: {formats:contains(PDF, , N/A)} Column_2 is a regular text column with permitted values, which has only one value: Yes. (Or empty, if it's a No). This is a "manual" column, where I myself select Yes when needed. Column_3 derives its values from the first two columns, either Yes, or N/A. I used the example of a relevant expression in the Calibre Manual online and came up with this: {#column_2:'ifempty($, field('#column_1'))'}. It works perfectly fine, correctly returning either Yes, or N/A, or empty. What I am struggling with, is the empty in Column_3. I would like it to say No, so that the column always has a value, either Yes, or No, or N/A. But as I said, I am not a programmer, so I wasn't able to fix the expression for column_3, so it would return a No when Column_2 is empty. It is always possible to add a No to Column_2, but I would rather avoid it, because Yes is a very rare occurrence, and it would mean I would have to manually add a No to every other book, when there might be a much easier solution. I would really appreciate if someone with the knowledge of Python (I am assuming, the expression above is in Python) could help me out with this. |
![]() |
![]() |
![]() |
#2 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,318
Karma: 7975240
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
First, the template language isn't python. It is something I made up.
It seems that the empty value is coming from #column_1. If I am right then this template should work. Code:
{:'first_non_empty(field('#column_2'), field('#column_1'), 'No')'} |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Junior Member
![]() Posts: 2
Karma: 10
Join Date: Nov 2019
Device: none
|
Thank you so much Charles! It works perfectly!
![]() |
![]() |
![]() |
![]() |
Tags |
column settings, columns, functions, python function, templates |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Plugboard, template, and custom composite column recipes | chaley | Library Management | 1047 | 04-24-2025 10:28 PM |
Using built-in template functions in a custom template function | ilovejedd | Library Management | 4 | 01-28-2018 12:20 PM |
Composite column template question | Anna_R | Library Management | 4 | 06-03-2015 03:59 AM |
Composite Column | BetterRed | Calibre | 12 | 09-01-2013 04:58 AM |
[Custom Column - Composite] Template Help Requested | Ealdwulf | Library Management | 2 | 06-16-2012 04:58 AM |