Possible to override a widget so that the widget content is used as the value of an attribute?

My question is probably better illustrated with the following example.

The $codeblock widget uses an attribute code, and ignores the content:

<$codeblock code="my code"/>

I’m wondering if there is a way to override the widget so that it uses its content as the value of the code attribute:

<$codeblock>
my code
</$codeblock>

I’m imagining something like:

\widget $codeblock()
<$genesis $type="$codeblock" $remappable="no" code=<<widgetContent>> />
\end

I can see that the content of a widget can be accessed via the $slot widget (https://tiddlywiki.com/#Custom%20Widgets), but obviously this can’t then be passed into another widget.

So is this at all possible with the new features in v5.3.0?

I have asked this recently, and as a rule widgets can’t provide a value to an attribute, because widget tend to only “write to the screen”. However there are other ways to get a block of wiki text containing widgets and macros etc… as code.

  • Thus we would wrap <$slot $name="ts-raw"/>

I am still not “fluent” in the new custom widgets, and still learning. I will return if I have a worked example. Slot and fill are what we use.

However macros do a decent job as long as you have your codeblock in a parameter or variable.

You can use 3 backticks this

```
your code
```

See: https://tiddlywiki.com/#Code%20Blocks%20in%20WikiText

You could also use the HTML tags like so:

<pre><code>your code</code></pre>

That’s the HTML code the first example creates

There are other ways too; depending on your need

$$$text/unknown
Some plain text, which will not be //formatted//.
$$$

Sorry I was not clear in my post, I don’t care about the $codeblock widget specifically, I’m just trying to understand what is possible with the new custom widget features.

\widget $code.block()
<$wikify name=content text="""<$slot $name="ts-raw"/>""">
<$codeblock code=<<content>> />
</$wikify>
\end

<$code.block>Contents</$code.block>

Though be careful with this. There is a reason why $codeblock takes an attribute instead of using its body. The contents of a code block is plaintext and shouldn’t be interpreted as wikitext, but as the body of a widget, it will be, which may cause parts of a codeblock to be processed or transformed before it’s printed out as a block as-is.

1 Like