ViewTemplate : works on individual tiddlers but not on transclusions/filter

Hello,

thanks to GrokTiddlywiki, I am able to understand a lot of things, especially the templates when viewing

BUT :slight_smile:

  1. it works correctly : when I open a single tiddler, the display is correct, taking into account the template based on the tag
  2. but when I transclude them (directly or with a search), the template view is not applied

Any idea ?

Thanks

Hello @szdavid,

I don’t know if I understand you. ViewTemplate= $:/core/ui/ViewTemplate ?

The templates works fine with filtered transclusion. In tiddlywiki.com you can try with this
{{{ [tag[HelloThere]] || $:/core/ui/ViewTemplate }}}

If you are talking about other thing, can you put basic examples?

Hello @Alvaro

Indeed, it seems I was not clear enough

I created a template to apply only to tiddlers with a specific tag “MyTag” ; For that, I used the code :slight_smile:

<$list filter="[all[current]tag[Contact]]">
  {{||ContactInformationTemplate}}
</$list>

if I open a tiddler tagged “MyTag”, it works.

But if I transclude the tiddlers (directly oor by search as you did), the default template is applied ; it makes sense as the containing tiddler is not tagged with MyTag and the fields are in the transcluded tiddlers, not the one I am currently reading

MAYBE I am wrong and it is necessary to ALWAYS precise the template to apply but I thought (hoped ?) that it would not be necessary ?
Is there a way for that to works ?

Real example :

Here is a tiddler : [[JohnDoe]] ;

  • it has fields such as phone, address,…
  • it has a tag Contact

I create a template tiddler [[$:/szdavid/TiddlerTypeTemplates/Contact]] tagged $:/tags/ViewTemplate

I add the following code in it :

<$list filter="[all[current]tag[Contact]]">
  {{||ContactTemplate}}
</$list>

and the tiddler ContactTemplate has this code :

<h2>{{!!title}}</h2>
<ul>
<li>Phone : {{!!phone}}</li>
</ul>

Now, when I open [[JohnDoe]], it displays correctly.

But if I transclude it in any tidller, it does not :

  • {{JohnDoe}}
  • {{{ [tag[Contact]]}}}

Thanks

I would imagine in that case that {{John Doe||ContactTemplate}} would work though - correct?

Yes, indeed, it does ; but I thought that I would be able to view the default template I applied for the individual tiddler itself, without having to remember which template I applied

Got it - well after doing some research, I’m stumped on how to do that, sorry. If the main issue is the remembering “which template”, I’m curious if another way of organizing it might help…

Could you have one tiddler tagged with the $:/core/ui/ViewTemplate and have tests for each of your types, so a [all[current]tag[Contact]]… then below [all[current]tag[Task]]… [all[current]tag[Project]]… type thing, name it something like MyTemplates and then just use that as a single template in all of your situations? I haven’t tested that, but just a thought.

When you use {{||ContactTemplate}} you are really using in the template the current tiddler. This sintax is equivalent to:

{{{ [<currentTiddler>] || ContactTemplate}}}

or

{{{ [all[current]] || ContactTemplate}}}

See https://tiddlywiki.com/static/Transclusion%20with%20Templates.html

When you use transclusion you don’t change the currentTiddler variable. You can see it in new tiddler with:

<<currentTiddler>>
{{JohnDoe}}
<<currentTiddler>>

This is actually a feature. You can use John Doe’s with a contact template, a business template, a sales template, etc. and present various aspects of the same data the way you want it for your current situation.

Note that when using the list widget you can specify a template attribute for displaying the results.

That is clear for me ; thank you !