Struggling with a transclusion from a state tiddler with a variable field name

I haven’t read the thread exhaustively, but here are some suggestions based primarily on your most recent code.

\procedure mod-select-actions()
<$action-listops $tiddler=<<book>>
	$field=<<advantage>>
	$subfilter="+[toggle{$:/temp/generated-list-mod-state}]"/>
\end

\procedure mod-select-option()
<option value={{!!title}}>
{{!!title}} ({{{ [{!!title}get[modifier-value]] }}}%)
<$list filter=`[<advbook>search:$(advantage)${!!title}]`>&#x2714;</$list>
</option>
\end

\procedure select-modsB(advantage, book)
<$select tiddler="$:/temp/generated-list-mod-state"
	default=""
	actions=<<mod-select-actions>>
>
	<option value="" disabled>Select modifier</option>
	<optgroup label="Special">
		<$list filter="[tag[GURPS Modifier]search:to-advantages:<advantage>]">
			<<mod-select-option>>
		</$list>
	</optgroup>
	<optgroup label="Global modifiers">
		<$list filter="[tag[GURPS Modifier]!has[to-advantages]] -[[Modifier template]]">
			<<mod-select-option>>
		</$list>
	</optgroup>
</$select>
\end
  • There’s nothing wrong with specifying a modTitle variable if you find it easier to follow, but in this case, I don’t think you really need it: you can omit it and use the default <<currentTiddler>>/{{!!title}} instead.
  • You shouldn’t be using an action widget as the value of an option; instead, use the actions attribute of the select widget. <option> values are used to specify the string that is actually written to the specified tiddler/field (as contrasted with what that option displays. In your case, I believe you want that to be {{!!title}}, i.e. the current $list item (your original <<modTitle>>).
  • Since you’re using the same <option> format for both optgroup lists, I moved it to a procedure that can be invoked as a variable to make your code a little more concise.
  • As @tw-FRed pointed out, you can’t use a <variable> as an operator suffix (as you were trying to do with <advbook>search:<advantage>). However, if we change the <% if ... %> syntax to a $list, we can make use of substituted attribute values and write the variable as <advbook>search:$(advantage)$ instead. By surrounding the filter in backticks rather than quotes, we indicate that the $(variable)$ should be substituted before the filter is evaluated.
  • Finally, as Fred suggested, you’ll want to write the selected value to a secondary tiddler and then append the value of that tiddler to your <<advantage>> field. Otherwise, any existing contents of that field will be overwritten by your selection.
    • toggle is intended to work with a title list, not a list of comma-separated strings, so I’ve amended your $subfilter to reflect this. Generally speaking, I’d recommend using title lists in your fields as they’re more filter-friendly, and adding commas in as necessary in your display templates (e.g. {{{ [<currentTiddler>get<advantage>enlist-input[]join[, ]] }}}).

I hope this gets you moving in the right direction! Let me know if any of this needs further explanation.