How to display a link to the template being used in the tiddler?

Hello TiddlyWiki Community,

I am working on a setup where a tiddler that uses a template tagged with $:/tags/ViewTemplate automatically displays a link to the corresponding template for easy editing.

My Current Setup

  • Template Example: $:/tags/ViewTemplate/tagsVIDEO
  • Template Content:
<% if [all[current]tag[VIDEO]] %>

<% if [all[current]has[resolution]] %>
resolution: {{!!resolution}}
<% endif %>
[[EDIT THE TEMPLATE|$:/tags/ViewTemplate/tagsVIDEO]]

<% endif %>

This works well when the link is hardcoded for a specific template, like $:/tags/ViewTemplate/tagsVIDEO.

The Problem

I have multiple templates (e.g., $:/tags/ViewTemplate/tagsAUDIO, $:/tags/ViewTemplate/tagsIMAGE), and I want to dynamically generate the link to the template that is being used for each tiddler.

For instance, if a tiddler has the AUDIO tag, the link should automatically point to $:/tags/ViewTemplate/tagsAUDIO.

However, I don’t know how to retrieve the title of the template being used dynamically.

What I Need Help With

  1. How can I dynamically retrieve the title of the template being used in a tiddler and display it as a clickable link?
  2. Is there a best practice for linking back to templates in such setups?

Any advice or examples would be greatly appreciated!

Thank you in advance for your help.

Take a look at $:/core/ui/ViewTemplate. This is the TWCore shadow tiddler that renders each tiddler from individual parts tagged with $:/tags/ViewTemplate. It does this using the following wikitext code:

<$list filter="[all[shadows+tiddlers]tag[$:/tags/ViewTemplate]!is[draft]]" variable="listItem">
<$transclude tiddler=<<listItem>>/>
</$list>

Note the $list widget uses variable="listItem". When each view template component is being rendered, the name of that view template is help in the listItem variable.

Thus, for your use-case, you can create the desired link using:

<$link to=<<listItem>>>EDIT THE TEMPLATE</$list>

enjoy,
-e

2 Likes

Thank you for your response.

I believe my initial explanation was insufficient, so I’d like to provide more context for my issue.

What I am aiming to achieve is creating a dynamic link to $:/tags/ViewTemplate/tagsVIDEO without hardcoding it directly into the template.

As I create many templates like $:/tags/ViewTemplate/tagsAUDIO, $:/tags/ViewTemplate/tagsIMAGE, $:/tags/ViewTemplate/tagsPERSON, I wonder if it’s necessary to manually enter the template name each time.

Ideally, I would like to write something like this into the template:

<$link to=<<currentTiddler>>>EDIT THE TEMPLATE</$link>  

However, since <<currentTiddler>> resolves to the calling tiddler, not the original template title, this approach does not generate the correct link to $:/tags/ViewTemplate/tagsVIDEO or other templates.

I am looking for a technique or method that allows me to dynamically generate links to the original template titles without hardcoding them.

Specifically, I need edit links to the templates being used for displaying content, rather than generating links for all templates as the solution you suggested. For example, if a tiddler has the VIDEO tag but not the AUDIO tag, I need the edit link to $:/tags/ViewTemplate/tagsVIDEO. An edit link to $:/tags/ViewTemplate/tagsAUDIO would not be required.

You have misunderstood my solution. I was NOT suggesting that you add the $link widget code directly in the $:/core/ui/ViewTemplate definition (which would generate links for “all templates”). Rather, you simply place

<$link to=<<listItem>>>EDIT THE TEMPLATE</$list>

into only those templates that you want to link from. By using <<listItem>> you don’t need to “manually enter the template name each time”, thereby achieving your stated objective.

-e

2 Likes

Thank you for clarifying your solution.
It has helped resolve the problem, and I truly appreciate your help!

Looks like you already have a solution, but another way I think would work is to use the thisTiddler variable.

New in v5.3.0 The thisTiddler variable is set by the $transclude widget to contain the title of the tiddler that was transcluded.