Would there be any general use for a first_in_list(val, separator, value [, value]*) type function?
It would check a list for each pattern in order, and then return the found list item as the value.
Template: first_in_list($tags, ',', "Fanfiction.Crossover")
List contents: Fanfiction.Crossover, Fanfiction.Half-Life & Portal, Fanfiction.Mass Effect
Template value: Fanfiction.Crossover
Template: first_in_list(list, ',', "Explicit", "Mature Audiences", "Teen and Up Audiences", "General Audiences", "Not Rated")
List contents: General Audiences, Explicit, Not Rated, Not Rated
Template value: Explicit
Regex pattern matching may be useful but as with the in/inlist, it lead to unintended results:
Template: first_in_list(list, ',', "foo", "^foobar")
List contents: foobar, foo, bar, bar, foo
Template value: foobar
whoops! the regex matched 'foo'
EDIT: Perhaps as a custom function.
Last edited by ownedbycats; 01-11-2023 at 07:50 AM.
|