mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-10-23 02:55:48 +00:00
53 lines
1.6 KiB
Plaintext
53 lines
1.6 KiB
Plaintext
created: 20221007144237585
|
|
modified: 20221007145934733
|
|
tags: Concepts Reference
|
|
title: Custom Widgets
|
|
type: text/vnd.tiddlywiki
|
|
|
|
!! Introduction
|
|
|
|
A <<.def "custom widget">> is a special kind of [[procedure|Procedures]] that can be called using the same syntax as widgets.
|
|
|
|
Custom widgets can also be used to override built-in JavaScript widgets to customise their behaviour.
|
|
|
|
!! Defining Custom Widgets
|
|
|
|
Custom widgets are usually defined with the [[Pragma: \widget]]:
|
|
|
|
```
|
|
\widget $$my-widget(attribute:"Default value")
|
|
This is the widget, and the attribute is <<attribute>>.
|
|
\end
|
|
```
|
|
|
|
The name of the widget must start with one or two dollar signs:
|
|
|
|
* A ''single dollar sign'' is used to override existing core widgets
|
|
** for example, `$text` or `$codeblock`
|
|
* ''Double dollar signs'' are used to define a custom widget
|
|
** for example, `$$mywidget` or `$$acme-logger`
|
|
|
|
|
|
The <<.wlink "GenesisWidget">> widget For example:
|
|
|
|
|
|
|
|
|
|
!! Using Custom Widgets
|
|
|
|
The name wrapped in double angled [[brackets|Brackets]] is used a shorthand way of [[transcluding|Transclusion]] the snippet. Each of these <<.def "procedure calls">> can supply a different set of parameters:
|
|
|
|
```
|
|
<<my-procedure>>
|
|
<<my-procedure "The parameter">>
|
|
```
|
|
|
|
The parameters that are specified in the procedure call are made available as variables.
|
|
|
|
!! How Custom Widgets Work
|
|
|
|
Custom widgets are implemented as a special kind of [[variable|Variables]]. The only thing that distinguishes them from ordinary variables is the way that they can be called as a custom widget with attributes mapped to parameters.
|
|
|
|
!! Using Custom Widgets
|
|
|