Folks,
I am exploring a way to make use of parameter $param$ and variable $(varname)$ substitution to create a “form”. This is a little “blue sky” research of a “proof of concept” for a larger idea so wondering if anyone can see a way forward.
This easy to do inside a macro;
\define macroname(param)
$param$ went to $(varname)$.
Regards $(othervar)$
\end
<<macroname "I">>
- Note how you must define and call the macro all in a tiddlers text field. Of course you can do this in a global macro (a tiddler tagged $:/tags/Macro) but this too still needs the define.
I am wondering if there is way we could have a tiddler/text field contain only the text such as follows;
$param$ went to $(varname)$.
Regards $(othervar)$
- Then the above can be used in a macro
- However there seems no way to transclude a text field into a macro, defined elsewhere, that the substitutions still work.
- It seems the substitution occurs before transclusions - understandable, but is there a way to force substitutions after transclusion?
Any tips, tricks, hacks or even guesses appreciated.
Hi @TW_Tones as you’ve discovered, macro definitions via the \define syntax have special capabilities that can’t be replicated with the <$set> widget etc. I do plan to extend the <$set> widget to unlock those hidden capabilities:
- To be able to mark a variable as a macro so that it gets the special textual substitution of parameter and variable values
- To be able to specify parameters for the macro
There’s also a plan to add a new mechanism specifically for efficient textual substitution – see Add support for string literal attributes with textual substitution · Issue #6663 · Jermolene/TiddlyWiki5 · GitHub
But right now I think you’d have to approach things via the search-replace operator.
So @jeremyruston I assume with the improvements to the set widget I may do something like this to get my desired result.
- I just put ismacro to indicate how one triggers this.
<$let othervalue={{!!fieldname}}>
<$set name=mytemplate value={{mytemplate}} ismacro>
<<mytemplate param:"param value">>
</$set>
- Where mytemplate tiddler contains a text with content and various substitutions of $param$ and $(othervalue)$
- I believe since the $set must be closed, it will force this example to be placed in a view template or similar cascade body, if I want to hide the code.
- One reason to use substitution is the result is “plain text” unless the value contains wikitext, which is what we want if we want a template with “plain prose” like a letter with substitutions, or the old fashioned “mail merge”.
- As I have asked before a less intrusive alternative to
<$text text={{{ filtered }}}/> etc… would be good.
Thanks for considering this issue. I feel solutions of this type will provide opportunities for naïve users to use tiddlywiki to build “document/letter/email templates” with little more than knowledge of the values to use as substitutions.