View Single Post
Old 03-16-2025, 08:52 AM   #1
JohnAndJane
Junior Member
JohnAndJane began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Mar 2025
Location: Germany
Device: Tolino Shine
Problem with template function

Hi,
I want to decide how to construct the filename depending on a tag entry.

Simple code for testing the tags...

Code:
program:
if list_contains(field('tags'), ',', 'Western') then
    strcat('true ->' , field('tags'), '<-')
else
    strcat('false ->' , field('tags'), '<-')
fi
For example two books running in the template function editor gives the following values
Code:
true ->Science Fiction<-
true ->Heftserie, Western<-
But there is something wrong in my code because it returns always true.
So I tried some other code.
Code:
program:
if list_contains(field('tags'), ',', 'Western',1,0) then
    strcat('true ->' , field('tags'), '<-')
else
    strcat('false ->' , field('tags'), '<-')
fi
Same behavior, next try with
Code:
program:
_is_in = list_contains(field('tags'), ',', 'Western',1,0);
shows
Code:
1
0
for the example above. Fine, but if I try to test the variable
Code:
program:
_is_in = list_contains(field('tags'), ',', 'Western',1,0);
if _is_in = 1 then 'true' else 'false' fi
or with
Code:
program:
_is_in = list_contains(field('tags'), ',', 'Western',1,0);
if _is_in then 'true' else 'false' fi
you get
Code:
1
1
for the example above.

Seems to be on a wrong way - someone can help?

Using Calibre 7.26.0 on Win 11 Pro
JohnAndJane is offline   Reply With Quote