This page is part of a static HTML representation of the TiddlyWiki at https://tiddlywiki.com/

function Operator (Examples)

These examples use the following predefined variable:

  • subTiddler: $:/SiteTitle

They also use the following predefined functions:

\function get.destField(subTiddler,field) [<subTiddler>get<field>]

\function get.sourceField(subTiddler,field) [<subTiddler>shadowsource[]get[text]jsonget[tiddlers],<subTiddler>,<field>]

\function get.sourceFields(subTiddler) [<subTiddler>shadowsource[]]:map:flat[<subTiddler>subtiddlerfields{!!title}]

\function has.diff(subTiddler,field) [get.destField<subTiddler>,<field>else[]]:filter[get.sourceField<subTiddler>,<field>else[]!match{!!title}]

\function diff.fields(subTiddler) [get.sourceFields<subTiddler>] [<subTiddler>fields:exclude[created creator modified modifier]] :filter[has.diff<subTiddler>,{!!title}]

[function[get.destField],<subTiddler>,[text]]
→ get the overriden value of the field text.

The function get.destField use the operator get to get the overriden value of the field text for $:/SiteTitle.

[function[get.sourceField],<subTiddler>,[text]]
→ get the original value of the field text

The function get.sourceField use the operator shadowsource to get the title of the plugin in which the shadow tiddler is defined ($:/core). It then use the operator get to retrieve the content of the field text, in which is defined every tiddlers for that plugin, in a json format. Next, the operator jsonget is used to retrieve the value of the original field text for $:/SiteTitle.

[function[get.sourceFields],<subTiddler>]
→ get the original list of fields.

The function get.sourceFields use the operator shadowsource to get the title of the plugin in which the shadow tiddler is defined. The subsequent Map Filter Run Prefix iterate over the plugin title, and use the operator subtiddlerfields to output every fields of the shadow tiddler $:/SiteTitle, whose title is retrieved using a TextReference.

[function[has.diff],<subTiddler>,[text]]
→ compare the original value of the field text with the value set in the overriding tiddler. If the value is different, output the overriden value

The function has.diff use the operator get to retrieve the current value for the field text. If this field is missing or empty, the operator else output an empty string. Next, the Filter Filter Run Prefix use the function get.sourceField to get the original value for that field, and the operator match is used to check if the value does not match the current value for that field, using a TextReference. If the values do not match, it means that the value for that field was changed, and the value of the field is output. Otherwise, the :filter filter run prevent the field value to be output.

[function[diff.fields],<subTiddler>]
→ list the overriden fields

The function diff.fields use the the function get.sourceFields to list every fields in the original $:/SiteTitle. It then use the fields operator to get every fields on the overriding tiddler, excluding the fields that are automatically set when a ShadowTiddler is overriden (created, creator, modified, modifier). The subsequent Filter Filter Run Prefix use the function has.diff to output only the title of the fields that were overidden.

Tip
Theses functions can be used together to highlight the changes made to $:/SiteTitle:

<$list filter="[diff.fields<subTiddler>]" variable=field>
  <$diff-text source={{{ [get.sourceField<subTiddler>,<field>] }}} dest={{{ [get.destField<subTiddler>,<field>] }}} >
    <code><<field>></code>: <<diff-count>> difference<%if [<diff-count>!match[1]]%>s<%endif%>
  </$diff-text>
</$list>

That renders as:

type: 1 difference
text/vnd.tiddlywiki
text: 2 differences
My TiddlyWiki @@font-size:small; v<<version>>@@