Link color field values

I’m using two tags, book and audiobook. I want the latter to get its color field value from the former. I’ve tried setting audiobook's color field value to {{book!!color}} but it doesn’t work, though it looks like it should work:

What am I missing?

My guess is that your setting results in the value to literally be the transclusion rather than then evaluated transclusion.

I would think that you can get around this by not actually setting the color field for the latter but using a separate stylesheet to enforce the transcluded color. Basically something along the lines of

tags: $:/tags/Stylesheet
type: (don't set this to text/css, leave it empty)
text:
\define ab-col() [data-tag-title] {background: $(color)$; }

<$let color={{book!!color}} >
<<ab-col>>
</$let>

I didn’t try the above but something along those lines should work. Maybe others have a better idea.

This is exactly the case, because the color field value is not wikified, so transclusions don’t work there.

HOWEVER…here’s a little trick that does work:

The $:/config/TiddlerColourFilters/color-field shadow tiddler defines a filter that is used in a cascade to determine when to apply the !!color field value to a tiddler. By default, this shadow tiddler contains:

[has[color]then{!!color}]

Edit this shadow tiddler and change the filter definition to:

[get[color]removeprefix[{{]split[!!]first[]get[color]] ~[has[color]then{!!color}]

What this does:

  • Get the color field value. Note that get[color] only returns a value if the color field has a non-blank value, so it implicitly applies the has[color] test.
  • Look for a {{ prefix in the color field value and remove it.
  • Split the remaining field value at the !! and take the first[] part to get the title of the tiddler being “transcluded”
  • Then, get the color field value from that tiddler

Note that, if the tiddler doesn’t have a color field value, or that value doesn’t start with {{, or the referenced tiddler doesn’t have a color field, or that color field value is blank, then the filter uses the previously defined TWCore standard test for when to apply a color field value.

Let me know how it goes…

enjoy,
-e

It worked!

I do feel a little uneasy editing a shadow tiddler for something this trivial tbh. I’m not confident enough with TW’s inner workings, it’s not clear to me what else would be affected by this change.

Would it be possible to use something to wikify the {{book!!color}} in-place, so the actual color value would be passed without fiddling with the system’s internals?

The TWCore expects the color field value to contain a literal color value using #rgb, #rgba, #rrggbb, #rrggbbaa or an X11 color name (e.g., “red”, “blue”, etc). Thus, there is no opportunity for “in-place” wikification of the color field value.

My suggested edit to the $:/config/TiddlerColourFilters/color-field shadow tiddler is essentially detecting when the color field contains {{tiddlername!!color}} and then “manually” resolves that reference ONLY for that very specific limited syntax which requires that:

  • The tiddler has a non-blank color field whose value starts with {{
  • The referenced tiddler exists and has a non-blank color field

If any part of those conditions are not met, it falls back to the standard default “cascade” filter. Thus, it’s just about as safe as it can possibly be. Of course, the simplest solution is to skip the “color transclusion” issue entirely, and just manually enter the same color field value directly into both the “book” and “audiobook” tiddlers.

-e

1 Like

Addendum:

Since you are using color field values in your TiddlyWiki, you might want these TiddlyTools add-ons:

TiddlyTools/Templates/Color and TiddlyTools/Settings/Colors/X11

They provide an enhanced color edit field that shows both the entered value and a “color swatch”.

When focus is in the color text input, it shows a droplist of X11 colors to choose from. The color swatch handles a much wider variety of CSS color syntax and clicking on it shows a system-provided platform-specific “color picker” interface.

See TiddlyTools/Templates/Info for documentation.

-e

1 Like

The $:/config/TiddlerColourFilters/color-field is a configuration tiddler. They are designed to be edited by users.

If users stop to change configuration tiddlers, because the core contains defaults, how should we make functionality configurable?

1 Like

@EricShulman if one follows these links, a user may not know how to use them without your subsequent note;

So perhaps you could include a comment in the templates linking to TiddlyTools/Templates/Info in each template. It will make it a little easier to make use of.

@EricShulman thank you again for the detailed explanation of how things work.

@pmario you’re right, I wasn’t clear enough on the nature of the change. It felt more like a hack but you made it clear that it’s actually a sanctioned configuration method.