Different templates in the story river depending on a tag.

230 views
Skip to first unread message

Luis Gonzalez

unread,
Feb 17, 2020, 8:13:54 AM2/17/20
to TiddlyWiki
Usually in the story river all tiddlers are shown with the same ViewTemplate: you can see the Title, Subtitle, tag zone and the content. But imagine you can see different content depending on a tag when you open the tiddler (witth other view template). It would be like having several types of tiddlers:

  • The usual tiddlers
  • Tiddlers with sub-stories inside (not reordered and reordered).
  • Ttiddlers that show some fields
  • etc.

I know you can apply a stylesheet depending of a tag or some field: https://tiddlywiki.com/#Custom%20styles%20by%20data-tags.

Is there any way to apply different templates in the story river?



Mark S.

unread,
Feb 17, 2020, 9:32:15 AM2/17/20
to TiddlyWiki
You can add features to a tiddler depending on tag easily enough.

Make a tiddler and tag it $:/tags/ViewTemplate

In the content, create sections following this pattern:

<$list filter="[all[current]tag[mytag]]">
.... whatever you want to present, such as fields, additional information, etc.
</$list>
... other sections for other tags, fields, etc.

You can rearrange the output by closing the tiddler, clicking on the $:/tags/ViewTemplate tag, and then moving your new tiddler up or down in the stack.

Changing existing portions of the tiddler (such as the tags) would require you to hide the existing sections by removing their
$:/tags/ViewTemplate tag, and writing your own replacement.


HTH

Mohamed Amin

unread,
Feb 17, 2020, 4:05:49 PM2/17/20
to TiddlyWiki
Changing existing portions of the tiddler (such as the tags) would require you to hide the existing sections by removing their
$:/tags/ViewTemplate tag, and writing your own replacement.

Would you please give more details, as I didn't get this point 

Mohamed Amin

unread,
Feb 17, 2020, 4:25:20 PM2/17/20
to TiddlyWiki
Sorry for jumping in, but I think my comment/question is related to this post (if not, I'll create new post)

@Mark

To be more specific about my question above, let me explain what I understand :-

  1. By default,  TW5 render ALL tiddlers based on the following templates (taged with $:/tags/ViewTemplate):-
    • $:/core/ui/ViewTemplate/title
    • $:/core/ui/ViewTemplate/unfold
    • $:/core/ui/ViewTemplate/subtitle
    • $:/core/ui/ViewTemplate/tags
    • $:/core/ui/ViewTemplate/classic
    • $:/core/ui/ViewTemplate/body
  2. We need to change this behavior ONLY for the tiddlers tagged "myTag"
  3. As you suggested , we can create a new tiddler (myTemplate01) and tag it with "$:/tags/ViewTemplate" that contains our customization (I'm using your example with some modification) :
    <div class=myclass01>
  1.   <$list filter="[all[current]tag[mytag]]">
                .... whatever you want to present, such as fields, additional information, etc.
      </$list>
  1. </div>

    <div class=myclass02>
  1. ... other sections for other tags, fields, etc.
  1. </div>
  2. Now TW5, will use the following Templates to render ALL Tiddlers (let's ignore the order):
    • myTemplate01
    • $:/core/ui/ViewTemplate/title 
      $:/core/ui/ViewTemplate/unfold
      $:/core/ui/ViewTemplate/subtitle
      $:/core/ui/ViewTemplate/tags
      $:/core/ui/ViewTemplate/classic
      $:/core/ui/ViewTemplate/body

Now I've the following questions:
  1. How to prevent ALL tiddlers that NOT taged with "myTag" to render my new template? I know that the render output will be empty, but all CSS styles will still applied, Right? Any overhead?
  2. How to prevent Tiddlers that tagged with "myTag" to render the "standerd ViewTemplate" ?

Thanks in Advance

Mat

unread,
Feb 17, 2020, 4:52:46 PM2/17/20
to TiddlyWiki
@Luis, what Mark refers to are called "conditional viewtemplates" if you want a search term.

@Mohamed ...you want to get deep into the secrets eh?...the puppet master tiddler you're probably looking for is... $:/core/ui/ViewTemplate

<:-)

Mark S.

unread,
Feb 17, 2020, 5:10:56 PM2/17/20
to TiddlyWiki


On Monday, February 17, 2020 at 1:25:20 PM UTC-8, Mohamed Amin wrote:
<div class=myclass01>
  1.   <$list filter="[all[current]tag[mytag]]">
                .... whatever you want to present, such as fields, additional information, etc.
      </$list>
    </div>

    <div class=myclass02>
    ... other sections for other tags, fields, etc.
    </div>

If you want to apply the class per "mytag", you need to put it inside the <$list ....> . And you need to specify the anti-condition
in a separate list:

<$list filter="[all[current]tag[mytag]]">
<div class=myclass01>
.... whatever you want to present, such as fields, additional information, etc.
</div>
</$list>
<$list filter="[all[current]!tag[mytag]]">

<div class=myclass02>
... other sections for other tags, fields, etc.
</div>
</$list>

However, this all applies to adding a new feature to the viewtemplate. If you want to change an existing
portion of the view template, such as tags, then you need to do a little more hacking.

But before I go any further, if al you want to change are STYLES based on a tag, then you might not
need any of this. Each tiddler that has tags is wrapped in a div that has a data-tags attribute
which lists the tags that apply to that tiddler. So you can use a stylesheet tiddler to change
what the tiddler looks like based on its tags without having to make any code changes. Of
course, the minute you want to do something like display fields, then you need to do something
with  the tiddler template.





Mohamed Amin

unread,
Feb 17, 2020, 5:38:17 PM2/17/20
to tiddl...@googlegroups.com
Thanks a Milion Mark S. , it's more clear now.

@Mat, Yes, after Mark's comment regarding "Style inside $list" and "Anti-Condition" I think I can now play with "$:/core/ui/ViewTemplate"

P.S. , I'm using the "Standard Template Mechanism" ({{||MyTemplate}} to achieve "partially" that result (just sacrifice by the "text field") , but if I can get the above works, It'll be SUPPER

Luis Gonzalez

unread,
Feb 19, 2020, 8:27:00 AM2/19/20
to tiddl...@googlegroups.com
Thanks!!

I have created a little Tiddlywiki using this conditional templates. If you click the book icon it creates a "story tiddler" with more tiddlers inside it.


I want to internationalizate it but I'm not sure how to create the tiddlers with the messages (in spanish and english).
And the final step: group all in a plugin (not yet).


I'm still in the middle of the "mastering tiddlywiki" long journey...
empty.html
Reply all
Reply to author
Forward
0 new messages