Background
For a wiki I’ve been developing for a work project, I have a bunch of snippets I want to be able to copy and paste from a button in the TOC, using my text-free variant of copy-to-clipboard macro.
I wrote a recursive function to check whether a tiddler has the tag Snippet or whether one if its tags has the tag Snippet or if one of those tags has the tag Snippet, or…
It looks like this:
\function .step(tid) [<tid>tags[]] :map[is.snippet<currentTiddler>]
\function is.snippet(tid) [<tid>tag[Snippet]then[yes]] :else[<tid>!has[tags]then[no]] :else[.step<tid>]
and I use in in an override to toc-caption . (And yes, I know that this could have an infinite recursion problem; for a shared tool, I’d need to avoid loops; for the current usage, this is fine.)
I call it like this:
<% if [is.snippet<currentTiddler>match[yes]] %>
<$transclude $variable="clipboard-button" src={{{ [{!!text}] }}} />
<% endif %>
That’s all working fine.
(If you want to try it, this version uses Welcome instead of Snippet, suitable for dragging onto the main site: Copy snippet.json (1.0 KB). It should show a copy button on everything in the Welcome hierarchy.)
My Question
It clearly would be useful to make that function more generic. The tag name should be a parameter rather than hard-coded. When I tried to do this, it failed (the buttons didn’t show), and I can’t see why. The code is below. Any suggestions?
function .step(tagname, tid) [<tid>tags[]] :map[in.hierarchy<tagname>,<currentTiddler>]
\function in.hierarchy(tagname, tid) [<tid>tag<tagname>then[yes]] :else[<tid>!has[tags]then[no]] :else[.step<tagname>,<tid>]
called liike
<% if [in.hierarchy<Snippet>,<currentTiddler>match[yes]] %>
<$transclude $variable="clipboard-button" src={{{ [{!!text}] }}} />
<% endif %>
Any suggestions for better ways to do this are more than welcome, too!
BTW, I’ve been out-of-touch here for a few weeks. Work and other side projects have taken all free moments I have (and some not-so-free ones too!) If you’re waiting for anything from me, I apologize; feel free to DM me.