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

I changed the $:/core/ui/Actions/new-tiddler to automatically include a field.

Here is what I changed it to:

\define get-tags() $(textFieldTags)$ $(tagsFieldTags)$
\whitespace trim
<$vars textFieldTags={{$:/config/NewTiddler/Tags}} tagsFieldTags={{$:/config/NewTiddler/Tags!!tags}}>
<$action-sendmessage $message="tm-new-tiddler" tags=<<get-tags>> linkstyle="color:#ff0303;"/>
</$vars>

This works for when I click the new tiddler button, but when I have a missing tiddler and create it, the field isn’t automatically added? I searched for how missing tiddlers are created and I don’t see any tiddler related to it.

1 Like

You mean when have a missing tiddler in the story? That shouldn’t affect this.

Whenever I click the ‘New Tiddler’ button, TiddlyWiki creates a tiddler with a field called linkstyle with a value of "color:#ff0303;". This is what I want whenever I create a new tiddler. I also changed the tiddlers related to the ‘‘New Tiddler Here’’ button (i.e. the button that tags a new tiddler with the tiddler of the button you just pressed). My issue is when there is a missing tiddler in the story river and I create it, TiddlyWiki doesn’t add the linkstyle field.

Hi,

The Missing Tiddler body content is in $:/core/ui/ViewTemplate/body/default which transcludes $:/language/MissingTiddler/Hint, which in turn transcludes TW default edit button $:/core/ui/Buttons/edit.

You could change $:/language/MissingTiddler/Hint code but it wouldn’t change the behavior of the default view mode toolbar edit button (ie when you click on the missing tiddler “normal” edit button, like any existing tiddler).

Another solution would be to clone $:/core/ui/Buttons/edit tiddler, add your code in the clone, and configure TW to use your cloned button instead of the default one.

Hope this helps,

Fred

1 Like

Thanks for leading me in the right direction.

Since you are going to add this field to every tiddler going forward perhaps you could change things to use the color as the default linkstyle color? Then you need only set if it is not the default colour.

I am building a sort of second brain wiki and I am experimenting with having links to tiddlers be different colors depending on it’s status:

  1. Red
  • The idea defined by the tiddler’s title is BARELY OR NOT AT ALL REPRESENTED by the body, tags, and/or fields of the tiddler.
  1. Yellow
  • The idea defined by this tiddler’s title is PARTIALLY represented by the body, tags, and/or fields of this tiddler IN A UNORGANIZED WAY.
  1. Green
  • The idea defined by this tiddler’s title is FULLY represented by the body, tags, and/or fields of this tiddler IN AN ORGANIZED WAY.

So, since all tiddlers that are just created by default aren’t “complete”, I wanted to make the link color red.
All tiddlers are subject to change since they are my representation of my mental model. But, this idea helps me quickly at a glance figure out if I can “trust” a tiddler to do it’s job based on it’s title without having to click into it. I also sort by color in the All tab in the sidebar. This helps me quickly get a sense of how many tiddlers are “complete” or not, and it also gives me some direction in what areas to further develop.

Here is an example:

There are quite a few ways to achieve this and one that would do it for all tiddler links.

  • Do you want this to occur in all tiddlers, or only specific ones, or ones in a special list?
  • Keep in mind there is already a css link style assigned to links and this will need to be overridden to achieve this

Can you give a formal example of the conditions that give rise to 2 Yellow and 3 green, since when neither, they will be red.

I think my approach would be to design a list item template or tiddler to transclude when generating lists that should have this color determined, thereby leaving the default behaviour.

If you want it to occur for all links, I would recommend leaving the default as is an only coding for yellow and green when the conditions are met.

  • This can be done by redefining the $link widget using the Genesis widget, somewhat more involved technically.

Note " This topic has been solved" it would have being better to start a new topic and link to this one.

1 Like

Yea, I should have started a new topic. I am not sure how to move our discussions to a new topic. I think only moderators can do that?

I’ll look into setting the default color of links to red. If I have anymore questions, I’ll just create a new topic.

Thanks for the tips!

For what it’s worth, I recommend working with some semantic (meaningful) aspect of the tiddler being styled/colored, and applying the style/color based on that meaningful condition. Have your new-tiddler (or missing-tiddler) process apply the default tag (or field value) not as a color, but as a meaningful status.

For example, you could have tags such as “sketchy” “incomplete” “fully-organized” (or whatever you like), and set it up so tiddlers with those tags get corresponding colorful links automatically. Tags are great because the core already expects these to be associated with colors, and it’s simple to get those colors to carry over into linkstyle presentation. You can even make a drop-down so that these tags are mutually exclusive (choosing one removes any other from that set).

If you don’t want to use tag-space for this, there could be a field for this info, and again the linkstyle colors can be set to follow automatically.

I recommend this because TiddlyWiki projects should have a long life and should not require you to memorize quirky things like “the color #ff0303 goes with sketchy placeholder tiddlers”. If you decide to do an advanced search for sketchy placeholder tiddlers (say, to survey them and see about your priorities for next phase of work), you don’t want to need to reconstruct your exact shade of red in order to type it into the advanced search box.

Further, if you want to change how the colors attach to kinds of tiddler status (for a new palette, or to share your project with a colorblind friend, or just to get a nice sequence among four colors instead of three), you don’t want to go changing the color field of each affected tiddler (even with a tool such as Commander, though it would help!) while also needing to change custom tiddler-creation scripts with hard-coded hex color values. :grimacing:

My basic rule of thumb: if there’s a piece of information (such as “#ff0303 stands for rough-draft tiddler”) give that info a single place to be stored within your wiki, and make it possible to revise that decision in one place, with ramifications rippling out automatically. Good design decisions early in a project will help you stay flexible and make it possible to add more dimensions to your project. Take or leave, of course — and good luck with your project! :slight_smile:

2 Likes

To echo springers advice a tiddler can be anything, if you decide to make particular kinds of tiddlers don’t force it on all tiddlers.

I use a field called object-type on tiddlers with values such as reference, note, activity, project etc…

Thus at creation or later this makes the tiddler a particular object but it can be treated accordingly.

Then within or across object-type you could use a field such as status.

I tend to reserve tags for ad-hoc grouping or system tags.

2 Likes

So, when you give a tiddler an object-type does it automatically create other fields for you depending on what object-type it is? Or, do you just use that ONLY as a way to organize the different types of tiddlers in your wiki? Also, do you have any public wikis? I always like to look at different wikis to get inspiration.

To be honest, I never thought that I would ever need to change the colors associated with the conceptual status of the tiddlers. I could use Commander to change them if I needed to, but you are correct in saying that I should only need to change the hex code of a color in one place and have it automatically change everywhere else. Currently, I have a dropdown that shows up at the top of every tiddler. There are 4 options in that dropdown: n/a, fetal, draft, stable. Fetal tiddlers have red-colored links. Draft tiddlers have yellow-colored links. Stable tiddlers have green-colored links. The n/a option removes styles from the links (i.e. sets them back to the color that is associated with links by the palette; which in my case is blue) The guidelines that I use to choose the status of a tiddler is as follows:

I use this “plugin” : https://linkstyle.tiddlyspot.com/. Do you foresee any issues with scalability by using this “plugin”? It’s basically a really large CSS file that has a style for every tiddler title. Would this stop working if I had, say, 10,000 tiddlers?

Could you give me a starting point on how I could accomplish this? What widgets do you think would be of interest to me? How can I have it so that if I add a tag, TW automatically adds a field with a specific value?

I know and love linkstyle (by @twMat here). I have not seen any issues with having it scale ok. Of course, stylesheet calculation can get burdensome with thousands of affected items. If you hit performance issues, we could look into a solution that harnesses css classes more directly. But I have several thousand tiddlers covered by linkstyle without a problem.

So, one crucial piece of info is missing, here: that dropdown is putting its result (n/a, fetal, draft, stable), where, exactly? Is there a field where that word (not the color value) is stored? Once we know that, it’s easy to set up linkstyle so that those values can be added to the linkstyle stylesheet.

Here’s how the code looks if I want to have all tiddlers with tag “book” show their links with the color from the color field of the book tiddler (which also gives its color to the tag pill for book):

<$list filter="""[tag[book]]""">
<$vars tid={{!!title}} 
style="""color: {{book!!color}};""">
<<linkstyle>></$vars></$list>

That just goes into the linkstyle stylesheet tiddler ($:/LinkStyle/Stylesheet), below the default tiddler-specific bit (which filters for tiddlers that have one of the linkstyle fields). We’re just adding in another general rule for how to style links, piggybacking on linkstyle macro, but now based on something other than individual tiddler’s linkstyle fields.

See it in action at the bottom of the linkstyle stylesheet here:

https://biblio-springer.tiddlyhost.com/#%24%3A%2FLinkStyle%2FStylesheet

If you need help seeing how to adjust to your use-case, follow up here.

@TW_Tones may have different answers. Certainly TiddlyWiki is set up to have certain kinds of tiddlers created with fields present, with or without default substantive values. See the “new journal” button for how this works. You can set up tiddler-creation routines that set fields with values, however you like…

But at the wiki I just linked, above, you’ll also see a feature in action that is a bit different, but more convenient, for me. It’s a view template that applies only to certain kinds of tiddlers. One view template addition for bibliographic items (things with the field bibtex-title) prompts for field content in certain fields, if those fields don’t yet have content. To see it in action: Here’s a book tidler which does not yet have an image or abstract, so it displays with input areas for abstract and image-url: Biblio-Springer —

Once the fields are filled in, the input box gets out of the way. (One tricky thing is that this approach requires content to be pasted in. If you start typing, the input disappears as soon as one character is typed! For my use case, this works fine. A more careful solution is to have the input box for a field appear until/unless the value in the field meets some specified condition. You may want a dropdown or checkboxes instead of a text box, etc.)

1 Like

will add to @Springer’s above, that as long as you have the one field that identifies a tiddler as a particular type and thus can apply a view template for that tiddlers type, or uses a template via the cascades, you do not need to create the additional fields related to that type unless you have something to put in them.

  • Rather than create the fields and set values, from the beginning it makes sense to allow these fields to be created and set as needed.
  • If you do have multiple fields with values you can consider creating a custom new button that you select an object type and create new tiddlers from the template, with the prepopulated values.
    • However my experience suggests, if you need to set a pile of default values from the begining you do not have the best design, because default can just be that, if the field or value is not present it defaults to what you would enter, not actually enter. Why use up bytes to store a default value in every tiddler to start with?

Back to the lead question:
Missing tiddlers are in fact just that, it makes sense if you no longer want them missing, that on the display of the missing tiddlers body, you permit the creation of tiddlers from there, letting the user select an object-type, then this results in the tiddler being created and the relevant view template or cascade being applied, and this prompting to enter or select vales for object-type related fields.

  • In some informal work we are doing to make missing tiddlers a full citizen in tiddlywiki we know, in a missing tiddler, we can locate where it is mentioned, sometimes this may allow us to determine from the tiddler that lists the missing title, what type the new tiddler should or could be for example a project tiddler may suggest child tiddlers are project tasks.
  • Further, through customising the link widget we could even provide tools to create missing tiddlers from the initial missing tiddler link.
    • Thus you may describe your project with prose (written text), turning each step or task into a link within your prose, then manually (from an icon after the missing link) or batch we can then generate the tiddlers the missing links imply.
  • If you follow this just in time fields approach, only create or set them if the value is not the default, then you build your lists and templates to assume the default value for the field, if it is not present or empty.

Caveat

  • I use relink installed to maintain referential integrity of tiddler titles.
2 Likes

Before, I would store the actual color value in a field called linkstyle. So, for example, if I selected “fetal” from the dropdown, TW would add a field-value pair of linkstyle='color:#ff0303;'. I have now refactored the dropdown to add the actual word in a field called tiddler_status. So, in this case TW would create a field-value pair of tiddler_status=fetal. I used the commander plugin to add the tiddler_status field to all the other tiddlers with the corresponding actual word (i.e. fetal, draft, or stable).

This is the code I have for my new dropdown picker: (this is tagged $:/tags/ViewTemplate)

<$list filter="[all[current]!tag[bibtex-entry]!role[comment]]">
	<$select field="tiddler_status">
		<option value=""></option>
		<option value="fetal">fetal</option>
		<option value="draft">draft</option>
		<option value="stable">stable</option>
	</$select>
	[[(click here for criteria)|Criteria for choosing between fetal, draft, or stable as the tiddler status]]
	<br>
	<br>
</$list> 

How would I make it so that the a linkstyle field with the corresponding color value would be created when I pick a value from the dropdown?

I’ll have to revisit the comments you and @TW_Tones wrote in the future. I didn’t finish reading Grok TiddlyWiki or learn much about filters and view templates. I learned a little bit and then starting creating this “second brain” wiki. The funny thing is that I was thinking I should have some sort of “form” when I create certain tiddlers that prompts me to add values to predefined fields. I didn’t realize that I was basically thinking of what view templates are used for.

They are not normally used that way, but it is I think a smart way to do it.

Take a look at the link I sent, above, to a linkstyle variant that handles an automated batch all at once (through the list condition), rather than setting up each individual tiddler with a linkstyle field (Here is the link again) … the only thing that’s stored at the individual tiddler level is its actual tiddler_status value.

Look at the end of the custom linkstyle tiddler there (which I think @twMat helped me set up many years ago), and you see:

<$list filter="""[tag[book]] book""">
<$vars tid={{!!title}} 
style="""color: {{book!!color}};""">
<<linkstyle>></$vars></$list>

You want something analogous, like:

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

And similar for each other status. Then, if you want to change the color, and/or add another status with its own style details, you just change your linkstyle stylesheet in this one place. (Note my own variant points to the color field of the tiddler called “book”, so changing the color there takes advantage of the built-in color picker, but if you don’t change color often, that’s a marginal difference.)

You (or someone else with similar challenge) could surely have an even more flexible solution by taking advantage of the class field and its styling power, but I’m not able to offer a walk-through at the moment…