modify Association created by FormFunction

Hi,

I want to create a FormFunction dynamically which means the number and the names of variables asked for in the FormFunction can change.
Therefore I would need to have direct access to the Association created by the FormFunction, for example to Apply it’s values to an StringTemplate. So far I was not able to figure out how to access this.

Any help is highly appreciated.

Ulrich

At least I came up with something with will do the trick - whereas I was hoping for something more elegant…
I generate the form function fields and the association as strings.
Then I StringReplace these in a FormFunction string and call ToExpression and Evaluate on this.
It is working but would be interested in better solutions…

tmpl1 = “Today is Weekday and tomorrow it will Weather”;
tmpl2 = “My hous is build with a HousePart1 and a HousePart2 and
will have GardenPart in the garden”;
tmplbase = tmpl2;
placeHolder =
Union[StringCases[tmplbase, Shortest[“" ~~ x__ ~~ "”] → x]];
fffields = {“"a” <> ToString[#] <> “"”,
“"” <> placeHolder[[#]] <> “"”} → “String” & /@
Range@Length@placeHolder;
astxt = “"” <> placeHolder[[#]] <> “" → #a” <> ToString[#] & /@
Range@Length@placeHolder;
txt =
"
FormFunction[<<>>,
Module[{tmpl,as},

				tmpl=StringTemplate[tmplbase];\[IndentingNewLine]			  \

as=Association[<<>>];[IndentingNewLine]
ExportForm[Print[TemplateApply[tmpl,as]],"String"];
]&
]
“;
txt = StringReplace[
txt, {”<<>>" → ToString[fffields],
“<<>>” → ToString[astxt]}];
Evaluate[ToExpression[txt]][];

I am interested to see what you came up with: could you format your code using the formatting tools?
Thanks,
David

Sorry, I pasted it into the code section but it looks like many things have not been present corrently.
I attach now an notebook with the example code.

Ulrich