Templates and transclusion

Hi,
I’m new to TW and trying to get my head round transclusion and templates. Perhaps someone might be able to help.

The Use Case: I’m using TW to set up a system for managing online students and their lessons. For each student tiddler it should contain a list of the lesson they have received (links to tagged tiddlers with the student name as the tag. This works using:

<<list-links "[tag[Peter]tag[Lesson]]">>

where Peter is the name of the student as a tag.

But, I’ve been reading about templates etc … and have set up a StudentInformationTemplate and transcluded (?) that into each of the Student tiddlers (and set this to be included via the ViewTemplate).

Some success with showing the information fields for that student:

<table>
<tr>
<th>Email</th><td><a href="mailto:{{!!email}}">{{!!email}}</a></td>
</tr>
<tr>
<th>Parent</th><td>{{!!parent}}</td>
</tr>
<tr>
<th>Parent Email</th><td><a href="mailto:{{!!parent-email}}">{{!!parent-email}}</a></td>
</tr>
</table>

So what I’d also like to do is include a list of all the lessons for that student in the StudentInformationTemplate. Something like:

<h2> Lessons </h2>

<<list-links filter: "[tag[Lesson]!sort[lesson-date]]" >>

<ul>
    <$list filter="[tag[Lesson]!sort[lesson-date]]" variable="lesson">
        <li><$link to=<<lesson>>/></li>
    </$list>
</ul>

But this displays all tiddlers tagged with “Lesson” of course. What I’d like is only those lessons for the selected student, so when displaying Peter’s tiddler it calls on the StudentInformationTemplate to show only the lessons for Peter or Bob or whoever. Each lesson is on a separate Tiddler - I suspect this is the issue that I cannot quote work out!

Can that be done?

Hi @PianoMan55 and welcome to TiddlyWiki community!

In your template you can add the title of the current tiddler to the filter using the <<currentTiddler>> variable like this:

<h2> Lessons for <<currentTiddler>> </h2>

<<list-links filter: "[tag<currentTiddler>tag[Lesson]!sort[lesson-date]]" >>

<ul>
   <$list filter="[tag<currentTiddler>tag[Lesson]!sort[lesson-date]]" variable="lesson">
       <li><$link to=<<lesson>>/></li>
   </$list>
</ul>

Notice how the variable is surrounded by double angle brackets when used outside of any filter (like in the header), but only by single angle brackets when used inside a filter.

Fred

1 Like

Thank you @tw-FRed , I thought the <<currentTiddler>> might be required here. I tried in vain, but using the two angle brackets. I’m now curious about the difference between <currentTiddler> and <<currentTiddler>>. I expect it’s in the documentation …

That works great and the Student data is now being referenced correctly on each Student tiddler.

Now I’d like to get the tiddlers tagged Student into a master Tab View …

Thanks again for the accurate and speedy response - much appreciated.

I could not explain it better than Eric Shulman:
https://talk.tiddlywiki.org/t/how-to-pass-content-of-a-field-to-the-filter/8118/2

Fred

You might want to have a look at the tabs macro documentation.
Something along the lines of:

<<tabs tabsList:"[tag[Student]sort[]]" template:"StudentInformationTemplate">>

But be aware that inside a tab, the current tab tiddler title isn’t available in <<currentTiddler>> but in <<currentTab>>, so your template should be modified accordingly.

Fred

You can make the template work BOTH in tabs and “stand-alone” by adding the following line at the start of your template definition:

<$tiddler tiddler=<<currentTab>>>

Then, you can continue to use <<currentTiddler>> and <currentTiddler> in the rest of the template.

This line works because the value of <<currentTab>> is only defined when the template is rendered inside a <<tabs ...>> macro. When rendered OUTSIDE of a tab (i.e., when directly viewing a “student tiddler”), the value of <<currentTab>> is blank, and the $tiddler widget effectively becomes a “no-op”, leaving the value of <<currentTiddler>> unchanged.

enjoy,
-e

2 Likes

Thanks for the additional replies - much appreciated.

I got the transclusion in tabs working from another thread here, creating a tiddler $:/tutoring/templates/tab with:
<$tiddler tiddler=<<currentTab>>> <$transclude mode="block" tiddler="StudentInformationTemplate" /> </$tiddler>

And then in the tiddler with the tabs:

<<tabs tabsList:"[tag[Student]!has[draft.of]]" default:"Asha" class="tc-horizontal" template: "$:/tutoring/templates/tab">>

So much to learn …