[DOCS] Update [[Custom Widgets]] with new example for overriding LinkWidget (#9961)

* [DOCS] Update [[Custom Widgets]] with new example for overriding LinkWidget

* fix: non-svg link icon are now sizing properly

* replace HelloThere by list-link in the example for robustness

* Add class to span for better styling in Custom Widgets

* Fix typo in Custom Widgets.tid documentation

* Improve doc by using the proper macro to link widgets

* Change font size style to important for title icon

Updated the font size style for the title icon to be important.

* Update transclude and slot elements in Custom Widgets

Provide a fallback if no body for the link is given

* Enhance link widget to show icons conditionally

Updated the link widget to conditionally display an icon next to the link based on the target tiddler's icon field. Modified the rendering logic to use a conditional statement for the icon display.

* Change transclude height to size in Custom Widgets
This commit is contained in:
Théophile Desmedt
2026-08-07 22:05:06 +02:00
committed by GitHub
parent ceb0817176
commit 5143138c16
@@ -1,5 +1,5 @@
created: 20221007144237585
modified: 20240422084734129
modified: 20260807190532419
tags: Concepts
title: Custom Widgets
type: text/vnd.tiddlywiki
@@ -79,3 +79,34 @@ Python
<$let test="Tiger">
<$codeblock code=<<test>>/>
</$let>""">>
In this example, we override the <<.wlink "LinkWidget">> widget to automatically display an icon next to the link if the target tiddler has an `icon` field. We use the <<.wlink "ParametersWidget">> widget to capture all attributes passed to the original link and forward them to the underlying widget via <<.wlink "GenesisWidget">>:
<<wikitext-example-without-html """\widget $link()
\function link.icon()
[<params-var>jsonget[to]else<currentTiddler>get[icon]]
\end link.icon
\function link.text()
[<params-var>jsonget[to]else<currentTiddler>]
\end link.text
\whitespace trim
<$parameters $params="params-var">
<$genesis
$type="$link"
$remappable="no"
$names="[<params-var>jsonindexes[]]"
$values="[<params-var>jsonindexes[]] :map[<params-var>jsonget<currentTiddler>]"
>
<%if [<link.icon>]%>
<span class="tc-tiddler-title-icon tc-titlebar" style="fill:currentColor;font-size:11pt!important">
<$transclude $tiddler=<<link.icon>> size="11pt"/>
</span>
<%endif%>
<$slot $name="ts-raw">
<$text text=<<link.text>> />
</$slot>
</$genesis>
</$parameters>
\end
<<list-links "[has[icon]]">>""">>