Have a missing tiddler automatically have a field set (... also: linkstyle and condition-based templates)

You can use a VIEW template so that certain fields are always nudging you for input (if empty), even in view mode, as I noted earlier.

AND/OR, you can build an EDIT template so that when you’re editing a tiddler of a certain kind, field prompts are set up in a helpful arrangement.

Here’s a somewhat hasty example. At that same biblio site, there this edit template. It shows edit-field-widgets I want (including a drop-down selection for the common entry-types).

See it at work when you open up a bibliography entry in edit mode, you see prompts for various typical things that need to be filled in for a biblio entry:

How does TiddlyWiki know that this tiddler needs this particular color-by-number edit template ? I have used the Cascade for Edit Body: $:/core/ui/ControlPanel/EditTemplateBody

I’ve given instructions to the cascade, in the form of a tiddler tagged $:/tags/EditTemplateBodyFilter It has a list-before field (with blank value), so that the cascade checks this before resorting to the default edit template. The contents of the cascade condition tiddler (in this case) are:
[<storyTiddler>fields[]prefix[bibtex]then[$:/springer/edit-template/bibtex]]

So, this edit template renders exactly when a tiddler with bibtex- fields is put in edit mode.

This can be a good alternative to creating fields at the time of creating the tiddler, especially if some of those fields are optional, and you don’t want to clutter your tiddler with blank values. The edit-mode edit-text widgets for possibly-relevant fields can be shown (in edit mode) whether or not you will need or use those fields. The actual field will be created in the tiddler’s JSON record only once a value is assigned.

1 Like

Ohhh, I think I understand what you think I am trying to do. Correct me, if I am wrong. I am not trying to create ONLY a list of tiddlers that are color-coded based on a tiddler status. That was just an example. In my wiki, I use tags to define sub-ideas of an idea.

So in this case, all the top level tiddlers in the list (i.e. My Anki configuration, Use-cases for Anki <and what not to use it for>, When should I do my Anki reviews, …) are all tagged How I use Anki. The tiddler Anki add-ons that I think are essential is tagged My Anki configuration and so on.

The black square is the body of the tiddler. I wrote nothing inside of it. The list gets automatically created with this tiddler (tagged with $:/tags/ViewTemplate):

<$list filter="[<currentTiddler>is[tag]]">
	<br>
	<div style="background-color:#e0faff">
		''Tagged'' <<tag>>
		<$transclude  $variable="toc-selective-expandable" tag=<<currentTiddler>>/>
	</div>
</$list>

I also want the tiddler title to be color-coded everywhere. Here is a full view of a tiddler and an example of tiddler links that are color-coded but not only in a list.

So, I am guessing I can’t really avoid having the linkstyle field in a tiddler or maybe I need to edit the LinkWidget somehow to check if a tiddler has the tiddler_status field? If you think what I’m describing is still possible with your approach, I’ll look into it more by myself.

Wait, I think I figured out what I should change. I am going to try to change the $:/LinkStyle/Stylesheet tiddler to check for if a tiddler has a tiddler_status field instead of checking if a tiddler has a linkstyle field.

Thanks @Springer and @TW_Tones for the extra discussion and guidance.

That did the trick.

Here is what I changed my $:/LinkStyle/Stylesheet to :

\define linkstyle()
<$set name="uri" value=<<makedatauri """$(tid)$""" "text/plain">> >
<$list variable="urititle" filter="""[<uri>removeprefix[data:text/plain,]]""">
<style>
a[href="#<<urititle>>"] { <<style>> }
.tc-sidebar-lists a[href="#<<urititle>>"] { <<style>> }
a[href="#<<urititle>>"]:before { <<style-before>> }
a[href="#<<urititle>>"]:after { <<style-after>> }
</style>
</$list>
</$set>
\end

<$list filter="""[has[tiddler_status]tiddler_status[fetal]]""">
<$vars tid={{!!title}}
            style=color:#ff0303;
>
<<linkstyle>>
</$vars>
</$list>

<$list filter="""[has[tiddler_status]tiddler_status[draft]]""">
<$vars tid={{!!title}}
            style=color:#ff9900;
>
<<linkstyle>>
</$vars>
</$list>

<$list filter="""[has[tiddler_status]tiddler_status[stable]]""">
<$vars tid={{!!title}}
            style=color:#017310;
>
<<linkstyle>>
</$vars>
</$list>

I could probably make this more compact using filters more efficiently but I just wanted to show it quickly.

Isn’t that exactly what I was suggesting, with:

<$list filter="""[tiddler_status[fetal]]""">
<$vars tid={{!!title}} 
style="""color: #ff0303;""">
<<linkstyle>></$vars></$list>

…? Doing it that way bypasses the need to make a linkstyle field, with identical contents, in each of the tiddlers that fit the relevant condition.

Checking first for whether the tiddler has the tiddler_status field is redundant, here, though.

(There are situations here where you see filter bits like [has[color]get[color]] — and that’s because you can get some empty noise if you go straight to get[color] without checking to see if the tiddler even has the field. But in your case, the linkstyle filter can be as simple as [tiddler_status[fetal]])

ohhhh! I completely misunderstood what that was, sorry! I thought that you put that in each tiddler to create a list. I should have read it more carefully. Haha, I thought I came up with the solution based on your idea but I did the exact thing you were telling me to do.

EDIT: I just reread your messages… I don’t know how I misunderstood that.

1 Like
  • has[color] only gives a result (a tiddler title) if the tiddler has a color field with a non-blank value
  • get[color] only gives a result (the value from the color field) if the tiddler has a color field with a non-blank value

Thus, it would seem that get[color] by itself should always produce the same result as has[color]get[color].

Can you show an example of when this would not be the case?

-e