[tw5] Automatic display of field content toggled by tag

Hello everybody!
I am wondering how to display the content of a field in the head of a tiddler’s text area depending on a tag. To be more precise: If there a defined tag (let’s say “info”) is present on a tiddler, then there a line should be done like "<$view field=“myfield”/> above the actual tiddler content. This should be done automatically if the tag “info” is set.

What I found so far fiddling with the $:/core/ui/ViewTemplate is a way to display the myfield content at the beginning of each tiddler. This is not ideal, it really should be toggleable (by tag) and my solution works only in the tiddler default view. But we are making extensive use of the tabs macro in our Tiddlywiki and unfortunately the ViewTemplate-solution doesn’t work on tabs.

I was not able to figure out where in the depths of Tiddlywiki’s system the content of a tiddler is basically created. And not how to insert a tag-sensitive view-field command. Any ideas out there? Thanks a lot in advance!

Greetings

Oliver

Hi Oliver,

… This is not ideal, it really should be toggleable (by tag) and my solution works only in the tiddler default view. But we are making extensive use of the tabs macro in our Tiddlywiki and unfortunately the ViewTemplate-solution doesn’t work on tabs.

So I do understand you right, that you want the info-field, to be shown inside the tabs macro above the tiddler content. right?

The tabs-macro allows you to use a template. So it can be called as follows. See the new “template” parameter


<<tabs "SampleTabOne SampleTabTwo SampleTabThree SampleTabFour" "SampleTabOne" "$:/state/tab1" template:"info-tiddler-template">>

Create a new tiddler eg: info-tiddler-template with the following content: do not use the 3 backticks ``` … only the text between them.

\whitespace trim

<$list filter="[<currentTab>tag[info]">
<$transclude tiddler=<<currentTab>> field="info" />
</$list>

<$tiddler tiddler=<<currentTab>> >
<$transclude tiddler="$:/core/ui/ViewTemplate/body/default" mode="block"/>
</$tiddler>

Where the list-widget checks if the tiddler mentioned in the currenTab-variable has a tag “info”. If yes it shows that info using the transclude-widget.

The second code block uses the default core template, that is used for the tiddler body.

I did test it at tiddlywiki.com … If it doesn’t work for you just ask.

The following code adds a HTML HR … horizontal rule, so there is a visual indication that the info field is shown. … That’s just an example, so you see, where you can add additional conditional info text

\whitespace trim

<$list filter="[<currentTab>tag[info]">
<$transclude tiddler=<<currentTab>> field="info" />

<hr>

</$list>

<$tiddler tiddler=<<currentTab>> >
<$transclude tiddler="$:/core/ui/ViewTemplate/body/default" mode="block"/>
</$tiddler>

have fun!
mario

Hello mario, hello everybody!

Mario, thank you very much for your detailed answer. I was able to transfer your solution to my testing wiki and it works principally and I understand the way it works.
Unfortunately my indended field is in date format. The output of the described tiddler-template-solution is as an unformatted string like 20220829. I could not find a way to enter working format parameters in the transclude line in the template. Do you perhaps have an idea how to format the output to a readable date?

But after all this solution does sadly not address my whole problem. With this tabs-template-solution the definded field content of a tiddler is shown in tabs view, but not in the standard tiddler view. I was looking for a solution which shows the field content in both views.

What I found so far is:

  1. Manipulating $:/core/ui/ViewTemplate
    When I insert a $view field command in the $:/core/ui/ViewTemplate my field content is shown - if existing - at the top of any tiddler in standard view. Date formatting is possible, but I was not able to make this tag-sensitive. It is not seen in tab view. I am aware that manipulating the common ViewTemplate is a quite brutal way.
    Part of my $:/core/ui/ViewTemplate:
[<currentTiddler>is[shadow]is[tiddler]then[tc-tiddler-overridden-shadow]] [<currentTiddler>is[system]then[tc-tiddler-system]] [{!!class}] [<currentTiddler>tags[]encodeuricomponent[]addprefix[tc-tagged-]] +[join[ ]] }}}>
''Revisionsstand:&nbsp;<$view field="Stand" format="date" template="MMM YYYY"/>''
<hr>
<$list filter="[all[shadows+tiddlers]tag[$:/tags/ViewTemplate]!has[draft.of]]" variable="listItem">
<$transclude tiddler=<<listItem>>/>
  1. Manipulating $:/core/macros/tabs
    I inserted a $view tiddler line in $:/core/macros/tabs and my field content is shown in tabs view. Again, date formatting works but I clould not make it tag-sensitive.
    Part of my $:/core/macros/tabs:
<$reveal type="match" state=<<tabsState>> text=<<currentTab>> default="$default$" retain="""$retain$""">
<$transclude tiddler="$template$" mode="block">
''Revisionsstand:&nbsp;<$view tiddler=<<currentTab>> field="Stand" format="date" template="MMM YYYY"/>''
<hr>
<$transclude tiddler=<<currentTab>> mode="block"/>
</$transclude>
  1. CSS
    I was trying to enter some content via Tiddlywiki’s CSS interface, like so:
.tc-tagged-info:before {
content: "TEST";
}

This works with text, but entering html via ‘content’ seems to be not possible by design. Dead end again.

So, a bunch of questions are still open:
A. Is there a more elegant way to set up my plan of date field content beeing displayed in a tagged tiddler in both, the standard and the tab view?
B. If it has to be a deep manipulation, is it possible to manipulate Tiddlywiki on a single point, so that a date field content is displayed in a tagged tiddler in both, the standard and the tab view?
C. If it have to be the both points which I described in 1. and 2., can these be made tag-sensitive?

Thanks for your patience
Greetings

Oliver Hahn

Oliver,

This is a quick reply; perhaps I don’t fully understand your challenge. But it seems pmario’s solution worked EXCEPT for not showing date format, yes?

If so, you should just be able to replace the transclude bit (inside pmario’s initial list-filter, which checks for the info tag), and call the view widget instead, which allows you to specify format (modifying the template for the format to suit your needs):


<$view tiddler=<<currentTab>> field=info format=date template="DDth mmm YYYY 0hh:0mm:0ss" />

-Springer

Your request is OK. I think I could figure it out :wink:

General rule:

Please describe the requested result in plain text or create some screenshots with normal wikitext, but without the templates … Sometimes it’s possible to create a “mockup” with standard wikitext

If we only get broken code or code that doesn’t do what you want, it’s very hard for us to imagine, what you wanted, with code alone. The plain text helps much more. …

It is not seen in tab view. I am aware that manipulating the common ViewTemplate is a quite brutal way.
Part of my $:/core/ui/ViewTemplate:

It shouldn’t be needed to manipulate the ViewTemplate. … There are several mechanisms in place that allow us to avoid that.

My response below addresses the following paragraph only.

But after all this solution does sadly not address my whole problem. With this tabs-template-solution the definded field content of a tiddler is shown in tabs view, but not in the standard tiddler view. I was looking for a solution which shows the field content in both views.

My very first solution used the ViewTemplate cascade, but it only worked with the tiddler and not with tabs.

Infos of the active cascade can be found at:

ControlPanel → Info → Advanced → Cascades → View Template Body … tab

I assume you want something like this:

There are 3 template elements needed. …

1st tiddler:

Title → :/config/enable/body/header tagged: $:/tags/ViewTemplateBodyFilter

It’s responsible to enable the header in the standard tiddler body. … As the name suggests :wink: The ViewTemplate is dynamically configured.

Important: It needs a list-before field with the value $:/config/ViewTemplateBodyFilters/default

The content is a filter expression, that needs to return the name of the body-template. I used :/my/body/header/template here in the example. If you use it like this it’s a standard tiddler. But if you add a $ as the first character, it will be system tiddler and will not show up for your users.

System tiddlers can be found in the right sidebar → More → System … or with AdvancedSearch → System tab

title: :/config/enable/body/header
tags: $:/tags/ViewTemplateBodyFilter
list-before: $:/config/ViewTemplateBodyFilters/default

[all[current]tag[info]then[:/my/body/header/template]]

2nd tiddler:

:/my/body/header/template … Which contains the new header code

''Revisionsstand:&nbsp;<$view field="Stand" format="date" template="MMM YYYY"/>''
<hr>
{{||$:/core/ui/ViewTemplate/body/default}}

3rd tiddler:

info-tab-template … I did rename this one. In the finished product it may be $:/my/tabs/header/template
It got new code, so we can reuse the body-header-template … so changes are only needed in 1 place.

<$list filter="[<currentTab>tag[info]]">
<$tiddler tiddler=<<currentTab>> >
<$transclude tiddler=":/my/body/header/template" mode="block"/>
</$tiddler>
</$list>

As I wrote if your users shouldn’t see that stuff, you need to make them system tiddlers. They start with $:/ … The tiddler titles have to be manually adjusted in the code too.

There is a ZIP file attached, that I used for testing.

have fun!
mario

(Attachment custom-body-header-v3.zip is missing)

1 Like

Hello PMario!

Thank you so very much for your solution! It’s wonderful and fits now exactly the belongings of my organisation. I am very taken with your dedication and patience. And thanks especially for that $:/tags/ViewTemplateBodyFilter trick I didn’t know before, it’s that cool way I was looking for.

May I just add one remark to a small weakness of your code, just in case some other person would like to use that feature.

The list filter in :/my/tabs/header/template works only if the tag info is set. That leads to the effect that a tiddler without the info tag is not displayed in tab view at all. You can check that in your example with removing the info tag from the SampleTabOne tiddler and watching the result in test-tabs tiddler. I solved that with adding another complementary list filter in :/my/tabs/header/template. The template now looks like:

<$list filter="[<currentTab>tag[info]]">
<$tiddler tiddler=<<currentTab>> >
<$transclude tiddler=":/my/body/header/template" mode="block"/>
</$tiddler>
</$list>
<$list filter="[<currentTab>!tag[info]]">
<$tiddler tiddler=<<currentTab>> >
<$transclude tiddler="$:/core/ui/ViewTemplate/body/default" mode="block"/>
</$tiddler>
</$list>

So our demand is solved, thanks again for your help.

Greetings!

Oliver

May I just add one remark to a small weakness of your code, just in case some other person would like to use that feature.

That was intentional, to test your participation :)) …

… just joking


I solved that with adding another complementary list filter in :/my/tabs/header/template. The template now looks like:

<$list filter="[<currentTab>tag[info]]">
<$tiddler tiddler=<<currentTab>> >
<$transclude tiddler=":/my/body/header/template" mode="block"/>
</$tiddler>
</$list>
<$list filter="[<currentTab>!tag[info]]">
<$tiddler tiddler=<<currentTab>> >
<$transclude tiddler="$:/core/ui/ViewTemplate/body/default" mode="block"/>
</$tiddler>
</$list>

There would be a different way with a more complex filter construction. But I think “keep it simple …” wins here. It’s probably more flexible in the future.

well done :wink:
mario

By the way.

Most of the discussion is going on at: https://talk.tiddlywiki.org/ now. … Just to let you know.

-mario