I want to contstruct a complex string(namely content at ② and ④) with a variable(namely tocTag at ①), which is read from another tiddler. I tried several ways however none of them works.
In line ②:the variable tocTag is not passed into formatTemplate macro
In line ④:the variable tocTag is not be replaced either
And I know $xxx$ is used to substituted variables defined in parameters list, it is just an example in my code. So I want to know:
Any way to pass a variable into a macro, or
Any way to replace placeholder with a “local” variable, or
Is there a more simpler way to solve this problem
Thanks
\define lingo-base() $:/language/Sidebar/TabManager
\define formatTemplate(tocTag)
<div class="tc-table-of-contents">
<<toc-selective-expandable "$tocTag$">>
</div>
\end
\define add-tab-action()
<$list filter="[<stateTiddler>get[tabName]trim[]!is[blank]]" variable="ignore">
<$set name="tocTag" filter="[<stateTiddler>get[tagName]]"> # ① got tagName and assign to tocTag
<$set name="content" value=<<formatTemplate $tocTag$>> > # ② I want pass tocTag to another macro, however this won't work
<$action-createtiddler
$basetitle={{{ [<stateTiddler>get[tabName]] }}}
$savetitle="$:/temp/Sidebar/TabManager/new-tab"
text=<<content>> # ③ this works, however the content is wrong...
text="....$tocTag$..." # ④ this won't work, anyway to do substitution with the `content` variable
/>
</$set>
</$set>
</$list>
\end
In your example in add-tab-action you are using $tocTag$ which is not a named parameter, nor do you show the macro being invoked.
Within a macro the value of a variable can be substituted with $(varname)$ but since it is substituted make sure you delimit it such as “$(varname)$”.
This refers to variables set outside the macro, otherwise if set in the macro you must use <<varinmacroname>>
Alternatively you can use a filtered transclusion to concatenate using filters which allows variables and more to be used.
eg {{{ [<varname>] }}}
or {{{ [addprefix[-]] }}} or {{{ [<varname>] [[--]] [{!!fieldname}] [[$prmname$]] +[join[ ]] }}}
$(varname)$ can be used to substitute variables defined outside the macro. So you can change the formatTemplate macro to substitute the variable as defined outside the macro.
No that is untrue, however your example is incomplete, I can’t see where and how it is used, what uses the add-tab-action ? Nor can I replicate and edit this to help you. For example “get[tagName]” suggests you have a field named tagName do you?, where is it. Perhaps you mean <tagName>?
Could you make a bundle of tiddlers if installed on tiddlywiki.com I/we can troubleshoot with?, I assume you have modified it to @saqimtiaz suggestions?
Perhaps you could explain in plain English what you want and we can see if we can give you that?
A button when clicked retrieves a tagname from a state tiddler, then generates a tiddler that displays a table of contents based on that tagname and puts it in the sidebar?
Even this suggestion is incomplete because what set the state tiddler?
If you drop this tiddler tag-tagname.json (766 Bytes) in your wiki and rename it to a “tag: tagname” you also get a sidebar tab listing the items so tagged, try “tag: $:/tags/Macro”. This demonstrates some tricks I have discovered.
A button when clicked retrieves a tagname from a state tiddler, then generates a tiddler that displays a table of contents based on that tagname and puts it in the sidebar?
Even this suggestion is incomplete because what set the state tiddler?
This is very close to what I wanted. I’m implementing a SidebarTabManager, which facilitates adding/removing sidebar tabs. The following screenshot is a demo, and https://gist.github.com/Robin-Luooo/bfe215b57a97d680362c4c34a6103640 is my code (I’m blocked at creating sidebar tabs, and updating tab logic has not been implemented yet).
The problem I am seeing is that you are assigning the variable tocTag to the tagName field from the temp tiddler, however this tiddler has no such field.
Remember that temp tiddlers are not saved and do not survive a save and reload cycle.
Also suggest moving the add-tab-actions to the actions attribute of the keyboard widget.
Good idea for a SidebarTabManager. Inspired by my guess as to what you want I just built a tool to add to my tag handling buttons something like what you were doing.
Actually its really useful on tiddlywiki.com when learning.