Yes. See the template documentation:
https://manual.calibre-ebook.com/template_lang.html
Single-function template is pretty limited here though. Personally, what I do is have a custom GPM template in a composite (column built from other column) column,
#kobopath, to generate the value I want.. Then I insert it into the save template:
Code:
{#kobopath}/{title} - {author_sort:sublist(0,1,&)}
For tags and tag-like columns, the list functions such as
list_re() and
list_split() are your friend here. As an example, this template will take the first available 'Fanfiction.Whatever' tag and turn it into 'Fanfiction\Whatever':
Code:
program:
list_split(list_re($tags, ',', '^Fanfiction.(.*)$', 'Fanfiction/\1'), ',', 'ff');
If you're checking for formats, use
approximate_formats() as it's far faster.