hey all, sorry for the silly question. I've tried searching here and reviewing the template page, but I'm still stuck.
All I'm trying to do is find any $title which contains a colon or a hyphen, and move the second half to a custom #subtitle field.
Right now I have the find & replace working fine - the regex I use is two-stage (I don't know how to do it in one stage with the search and replace action) where I search for .+ ?[:-] (.+) and put the first match into the #subtitle field, then do a second search for (.+) ?[:-] .+ and replace the $title field with the first match, to remove the subtitle.
I'm trying to move these two saved searches into an action chain, though, and therefore I'd like to be able to just run it on any selection in my library. With the way I have it configured, though, this causes issues on books which don't have a [:-] in the title, due to how search & replace seems to work (if no capture groups exist, \1 just matches the whole search, so the full title will be transferred into #subtitle).
Anyway, what I'm trying to do now is to use a template scope to filter the action to only run on titles which contain [:-].
The problem I'm having is that I guess I'm just dumb and I can't figure out how exactly to just use a template to limit to a subset of my current scope. There's a contains(), but that seems to just give back text. I've tried downloading and reviewing a few chains posted here that have scopes, but it doesn't make much sense to me. I guess I haven't wrapped my brain around exactly how calibre templates work.
I'm sure this can all be done in one step, the main thing I have difficulty understanding is how incoming and outgoing variables are handled, or basically the 'state' of everything that I'm acting on.
Thanks for reading!
Last edited by noahkiss; 06-27-2024 at 10:13 AM.
Reason: trying to fix formatting
|