How to: Automatic setting field value if a tiddler has a special tag

249 views
Skip to first unread message

Surya

unread,
Jan 13, 2018, 6:39:38 PM1/13/18
to TiddlyWiki
Hello,

I'd like to have the field "caption" automatically set to a value, if a tiddler is tagged with Ja.

The value should be @@color:lightgreen;TheTitleOfTheTiddler@@

In this way the tiddlers tagged with Ja are shown in lightgreen letters on the sidebar.

How do I automatically set a field value?

And the problem is, that the title is always different.


I made the same with the background of the tiddler-title, tagged with Ja with:
div.tc-tagged-Ja .tc-tiddler-title { background-color: lightgreen; }
In that way, the background of the title gets automatically lightgreen, if it is tagged with Ja.

But how to do with the caption-field?

Regards, Surya

Birthe C

unread,
Jan 13, 2018, 7:03:14 PM1/13/18
to TiddlyWiki
Hi Surya,

How would that change color in the sidebar?

Birthe

Surya

unread,
Jan 13, 2018, 7:16:36 PM1/13/18
to tiddl...@googlegroups.com
Hi Birthe,

I discovered this great feature just a few days before :-)
if I have tiddler called joke and shown in the sidebar and write manually in the caption-field @@color:red;funny@@, then I see this tiddler like this in the sidebar
funny.

You can see it in my picture about the popup-problem in the task-list. In the sidebar on the right side there is one tiddler in lightgreen, the others are all in lightgrey.

But I would like to have that automatically done, because
1. it's less work :-)
2. This tag often changes and it's an important tag to see the difference between tiddlers in the sidebar.

TonyM

unread,
Jan 13, 2018, 7:18:46 PM1/13/18
to TiddlyWiki
The side bar displays the caption rather than title if they exist. By placing formats in the caption title it may change the display.

I would create a custom list and tag it to appear in the sidebar, ion that I would put the Color and logic there rather than in each caption. Perhaps have a caption Color field.

Tony

Birthe C

unread,
Jan 13, 2018, 7:27:56 PM1/13/18
to TiddlyWiki
Hi Tony,

I know that the sidebar displays caption rather than title - but with the colours set from the palette, is it not so? Changes in the palette changes a lot of other places too.


Birthe

Mark S.

unread,
Jan 13, 2018, 8:57:10 PM1/13/18
to TiddlyWiki
You don't mention what tabs you want this used in. It turns out that you can over-ride timeline behavior (used by the Recent tab and others) by making a tiddler with the following contents:

\define timeline-title()
<$list filter="[all[current]regexp:tags[\bJa\b]]" variable="dum">@@color:red;<$view field="caption"><$view field="title"/></$view>@@</$list>
<$list filter="[all[current]!regexp:tags[\bJa\b]]" variable="dum"><$view field="caption"><$view field="title"/></$view></$list>
\end

Make it global by marking it with $:/tags/Macro

Note that this uses regular expressions and can be 'tricked' if for some strange reason you tag something with "Ja Ja" or "Ja Ja Ja". In other words, depending on the tag name you pick, it might be confused by tags with multiple words in them.

Good luck

-- Mark

Surya

unread,
Jan 14, 2018, 7:27:28 AM1/14/18
to TiddlyWiki
Hi Mark,

I made a tab in the sidebar with a tiddler. In this tiddler I have table of content with
<div class="tc-table-of-contents">
<
<toc-selective-expandable 'Pflanzen-Wiki' sort[title]>>
</div>

Does your idea work there? Would I have to modify it?
The tiddlers, which should to be shown in another colour are tagged with "Pflanzen" and "Ja".

Mark S.

unread,
Jan 14, 2018, 12:33:47 PM1/14/18
to TiddlyWiki
In this case you could make a tiddler marked as global macro with the following contents:

\define toc-caption()

<$list filter="[all[current]regexp:tags[\bJa\b]]" variable="dum">@@color:red;<$view field="caption"><$view field="title"/></$view>@@</$list>
<$list filter="[all[current]!regexp:tags[\bJa\b]]" variable="dum"><$view field="caption"><$view field="title"/></$view></$list>
\end

Except that your new requirement for TWO tags changes the filter logic. Do you mean you want both tags to turn RED, or one tag to turn RED and the other GREEN ?

Good luck,
Mark

Surya

unread,
Jan 14, 2018, 1:25:47 PM1/14/18
to TiddlyWiki
Hi Mark,

Juhuu :-) (german word for being happy ;-)
It works :-)) Thanks!

The tiddlers tagged with Ja are always also tagged with Pflanzen. I just mentioned it, because I haven't been sure, if it is important to know for the macro.

Thanks, now I have a good overview in the sidebar with just a little piece of work :-)
Surya

Surya

unread,
Jan 31, 2018, 2:31:36 PM1/31/18
to TiddlyWiki
Hi,

again here :-)

Now I have the situation, that I want in another wiki to have 3 types of showing tiddlerlinks in the sidebar (shown there with toc-selective-expandable):

  • Some tiddlers have the tag "wichtig" >they should be shown red in the sidebar.
  • Some tiddlers have the tag "RezeptGetested" >they should be shown green in the sidebar.
  • Some tiddlers have the tag "RezeptNICHTGetested" >they should be shown orange in the sidebar.
I made it with building 3 different tiddlers, tagged with $:/tags/Macro with
\define toc-caption()
<$list filter="[all[current]regexp:
tags[\bTag\b]]"
variable="dum">@@color:Coulour;<$view field="caption"><$view field="title"/></$view>@@</$list>
<$list filter="[all[current]!regexp:tags[\bTag\b]]" variable="dum"><$view field="caption"><$view field="title"/></$view></$list>
\end

>Of course with the different tags & different coulours


And I made it with only 1 tiddler, tagged with $:/tags/Macro with the same command (but repeated 3 times- of course with the different tags & different coulours).


Both didn't work.
But it works, if I only make 1 tiddler with 1 tag + 1 coulour.

So, it seems, that, if there are 3 different conditions with resulting coulours, they disturb each other.

How to solve this?

Surya

coda coder

unread,
Jan 31, 2018, 3:29:29 PM1/31/18
to TiddlyWiki
Following the principle that teaching a hungry man to catch fish is better than feeding him a single fish...

You need a stylesheet that uses .tc-tagged-wichtig etc.

Read https://tiddlywiki.com/#How%20to%20apply%20custom%20styles%20by%20tag

Surya

unread,
Jan 31, 2018, 3:54:45 PM1/31/18
to TiddlyWiki
Hello coda coder,

thanks for your answer.



Following the principle that teaching a hungry man to catch fish is better than feeding him a single fish...

Yes, I like that principle and learned a lot by that in my whole life.

But, on the site, you mentioned, it is only written how to style the tiddler itself, nothing about "how to style the view in the sidebar of certain tiddlers".

 
And: What is written on the site, I already know and am able to do things like that.
And I know also how to make a tiddlerlink shown in a certain colour in the sidebar by tag.


But the problem is ....
see my post before...

Surya

Mark S.

unread,
Jan 31, 2018, 6:12:27 PM1/31/18
to TiddlyWiki
This seems to work:

\define toc-caption()
<$list filter="[all[current]tag[wichtig]]" variable="dum">@@color:red;<$view field="caption"><$view field="title"/></$view>@@</$list>
<$list filter="[all[current]tag[RezeptGetested]]" variable="dum">@@color:green;<$view field="caption"><$view field="title"/></$view>@@</$list>
<$list filter="[all[current]tag[RezeptNICHTGetested]]" variable="dum">@@color:orange;<$view field="caption"><$view field="title"/></$view>@@</$list>
<$list filter="[all[current]!tag[wichtig]!tag[RezeptNICHTGetested]!tag[RezeptGetested]]" variable="dum"><$view field="caption"><$view field="title"/></$view></$list>
\end

Notice I'm using the "tag" operator (which is simpler than regexp). Not sure why we were using the regexp operator before.

The problem was the logic. If you stack a bunch of lists like

<$list if tag wichtig> red
<$list if tag ! wichtig> plain
<$list if tag RezeptGetested> green
<$list if tag ! RezeptGetested> plain

Then you can see that there are going to be two list actions for "plain" -- so if something is "Red" then it will also be "not Blue", and so there will be 2 entries. If you stack 3 sets, then there will always be 3 entries.

The fix was to stack them like:

<$list if tag wichtig> red
<$list if tag RezeptGetested> green
<$list if tag not RezeptGetested AND not wichtig> plain

HTH

-- Mark

Surya

unread,
Jan 31, 2018, 6:38:41 PM1/31/18
to TiddlyWiki
Hey Mark,

YES :-) That works!

THANKS, Surya
Reply all
Reply to author
Forward
0 new messages