How apply a variable <div data-HERE >?

Searching the archives I don’t find anything about using a variable as the html data-attribute itself (not as its value), i.e <div data-HERE >hey</div>

The only way I succeed is by using a macro for text substitution like so

\define mymacro(foo) <div data-$(foo)$="true" >MY DIV</div>

<<mymacro bar>>

but this is not optimal because the div is actually already inside a procedure among other html stuff (see illustration here below) and it would make the code harder to read if I had to externalize my div:

\procedure myproc(foo)
<div>something</div>
<div data-<<foo>>=true >MY DIV</div>
<div>something</div>
\end

<<myproc bar>>

Is there a syntax that can work directly in the procedure? I’ve tried everything I can come up with. The forum has questions about variables as the attribute values, or as attributes in a wikitext widget, but I can’t find any where the question is “variable as a html attribute”.

Thank you!

Use the $genesis widget with the $names and $values attributes:
https://tiddlywiki.com/#GenesisWidget

Something along these lines:

<$genesis $type="div" $names=`data-$(foo)$` $values="true">MY DIV</$genesis>

Note that $names and $values are evaluated as filters.

2 Likes

Hahaa, that solves it and I would have never thought of that! It’s interesting how many solutions/techniques in TW are “out of mind” even if one did read about them at one time. I guess it is a consequence from the multitude of tools that TW features. And I guess the only solution is more doc examples and increased “searchability” to find them. I have an idea for this…

Anyway, thanks @saqimtiaz :grinning:

Help is highly appreciated.