$:/palette does not support text referencing

Merely curious as to why $:/palette does not support text referencing. This severely restricts the utility of $:/palette. Should it support text referencing or wikitext, I could employ conditional logic for selection and evaluation. Alternatively, I could delegate processing to another entry, requiring only the import of that entry’s values within $:/palette. However, after numerous attempts, I found this entirely unfeasible—even referencing its own field values proves impossible.

I’m curious as to why this is the case – is it a bug worth fixing, or was it deliberately designed this way?

Please give examples, text referencing is such a general term it’s almost meaningless.

there are a number of design considerations and workarounds so with a little more detail we can give a quick answer without spelling out all the details.

The $:/palette tiddler is simply a reference to a selected “dictionary tiddler” (e.g., $:/palettes/Vanilla) with type=application/x-tiddler-dictionary that contains a list of color indexes and values.

Within this dictionary tiddler, the values can be any valid CSS color (including hex, rgb(), or X11 color names). A value can also be a macro reference (commonly the <<colour>> macro, which “delegates processing to another entry”), or any other wikitext such as simple transclusion (e.g. {{myColor}}), filtered transclusion (e.g. {{{ [{MyColor}!match[]] ~[[pink]] }}}) or even more complex wikiscript syntax including conditional %if syntax.

Try this:

  • go to https://tiddlywiki.com
  • open $:/ControlPanel > Appearance > Palette
  • scroll to the bottom and click the “show editor” button
  • The 5th listed item is “General background”, with a default value of #ffffff
  • Change this value to {{{ [{MyColor}!match[]] ~[[pink]] }}}
  • The tiddler backgrounds (and some other page elements) will now be pink
  • Then, create a “MyColor” tiddler containing text red
  • The tiddler backgrounds (and some other page elements) will now be red

If this isn’t working for you, then there’s something else interferring with the TWCore standard handling for color palettes.

Also, you might like to try my enhanced TiddlyTools/Palettes/Manager which provides several nice TWCore-compatible features including:

  • A [+] button to add new custom entries to a palette definition
  • A summary “color map” that shows all colors being used. Click a map “swatch” for a popup to quickly assign a new color value to all palette entries that are using that color
  • “Undo” handling for each palette entry to revert to the last saved value
  • Each palette value edit field also has a popup (click the down arrow) to select from a list of available palette entries (plus “transparent” and “inherit”). If you install TiddlyTools/Settings/Colors/X11 then the list will also show 145 standard X11 color names.

enjoy,
-e

1 Like

It seems everyone misunderstood what I meant. What I was trying to say is that in $:/palette, the text field can only be written as a specific value like $:/palettes/FlexokiLight. But I want to write it as a field reference expression like {{!!test}}, or even a slightly more complex conditional expression.

Because I want to use different palettes in the same wiki but under different layouts, but currently this seems impossible. Similarly, $:/layout can only accept specific values and cannot accept the results of conditional expression processing.


Seems I misunderstood. I get EricShulman’s solution now.

The text field in $:/palette contains the name of the current palette dictionary tiddler.
The text field in $:/layout contains the name of the current page template tiddler.

To “use different palettes in the same wiki but under different layouts” you would simply change the values in BOTH the $:/layout and $:/palette tiddlers. Something like this:

<$button> Use Layout One
   <$action-setfield $tiddler="$:/layout" text="LayoutOne/PageTemplate"/>
   <$action-setfield $tiddler="$:/palette" text="LayoutOne/Palette"/>
</$button>
<$button> Use Layout Two
   <$action-setfield $tiddler="$:/layout" text="LayoutTwo/PageTemplate"/>
   <$action-setfield $tiddler="$:/palette" text="LayoutTwo/Palette"/>
</$button>

or, if you prefer to use a $select list:

\procedure changeLayout()
<$action-setfield $tiddler="$:/layout" text={{{ [{$:/state/currentLayout}addsuffix[/PageTemplate] }}}/>
<$action-setfield $tiddler="$:/palette" text={{{ [{$:/state/currentLayout}addsuffix[/Palette] }}}/>
\end
<$select tiddler="$:/state/currentLayout" actions="<<changeLayout>>">
   <option>LayoutOne</option>
   <option>LayoutTwo</option>
</$select>

-e

I chose another approach, but it doesn’t seem to be working. I set $:/palette to newVanilla, and newVanilla’s values are basically like the following. But the entire code isn’t taking effect. I suspect the wikification might have failed. Not sure how to improve the code.

newVanilla
alert-background: <<AH-Palette "alert-background" >>
alert-border: <<AH-Palette "alert-border" >>
alert-highlight: <<AH-Palette "alert-highlight" >>
alert-muted-foreground: <<AH-Palette "alert-muted-foreground" >>
background: <<AH-Palette "background" >>
blockquote-bar: <<AH-Palette "blockquote-bar" >>
button-background: <<AH-Palette "button-background" >>
button-foreground: <<AH-Palette "button-foreground" >>
\procedure AH-Palette(field)
<$set name="workSpaceName" value={{{ [all[tiddlers]tag[workspace]] :filter[get[workspace-ID]match{$:/info/tidgi/workspaceID}] }}} >
<$wikify
name="AH-Palette-value"
value={{{ [<workSpaceName>get[palette]getindex<field>] }}}
 >

123

<$wikify name="AH-P-V-R" text=<<AH-Palette-value>>>
	<<AH-P-V-R>>
<$text text=<<AH-P-V-R>> />
</$wikify>

456


* <<workSpaceName>>
* {{{ [<workSpaceName>get[palette]] }}}
* <<field>>
* {{{ [<workSpaceName>get[palette]getindex<field>] }}}
* <$text text={{{ [<workSpaceName>get[palette]getindex<field>] }}} />

<$text text=<<AH-Palette-value>> />

</$wikify>
</$set>
\end AH-Palette
<<AH-Palette "background" >>
123


456

* AH-Flex
* $:/palettes/FlexokiLight
* background
* #FFFCF0
* #FFFCF0

The $wikify params should be name=... and text=..., but you’ve used value=.... As a result, <<AH-Palette-value>> is blank instead of being the background index value

but when i use text=... , it also wrong.

too diffiuclt, i don’t want to try this again ,may dirictly set $:/palette is the best way.

i win, this is code .

\procedure AH-Palette(field)
<$set name="workSpaceName" value={{{ [all[tiddlers]tag[workspace]] :filter[get[workspace-ID]match{$:/info/tidgi/workspaceID}] }}} >
	<$let
		paletteName={{{ [<workSpaceName>get[palette]else[$:/palettes/Notion]] }}}
		paletteValue={{{ [<paletteName>getindex<field>] }}}>
	<$tiddler tiddler=<<paletteName>> >
		<<paletteValue>>
	</$tiddler>
	</$let>
</$set>
\end AH-Palette

Why is $<$tiddler tiddler=<<paletteName>>> needed?
Shouldn’t <<paletteValue>> by itself be sufficient to output the result?

Because many palettes contain expressions such as <<colour muted-foreground>>, and the colour macro does not support setting specific palettes, a tiddler widget must be added to handle this. This prevents expressions like <<colour muted-foreground>> from ultimately becoming empty.

This was the crux of the matter that had troubled me for two days.