Using Alternate Tiddler Titles

I have figured out how to nest <$link><$view><$view/></$view></$link> so that I can use a field set up on the tiddler as the alternate title for it. Is there a macro or something that will do this a little easier?

I figured I’d ask before I tried to make one, having never done that before.

Hi,
the magic is called Alias ViewTemplate.json (881 Bytes) and it has been made I think by @twMat some years ago.
Create a field “alias” fill it with your desired title and !importand set Tiddlertitles do display as Links.

@Travis_Garris Of course it depends when and where you want this alternative title used.

  • There is already the caption field that standard lists use if existing otherwise defaults to the title field.
  • @JanJo s above suggestion
  • Marios alias features in his uni-link plugin

You could spell out what you want a little more and perhaps we can hand you a custom solution.

If you want to use caption as title, so you can have two tiddlers have same title.

You can use TW5 CPL Wiki — TiddlyWiki5 Plugin Library for TiddlyWiki Chinese Communities plugin from CPL, you can switch language to English by click on the button on the left.
See TiddlyWiki-CPL: TiddlyWiki world of Google App Store! for how to use CPL.

You can always hack the tiddler $:/core/ui/ViewTemplate/title/default.

The default source code looks like this:

\whitespace trim
<h2 class="tc-title">
<$view field="title"/>
</h2>

You can change this to something like this:

\whitespace trim
<h2 class="tc-title">
  <!-- check to see if your field exists -->
  <$list filter="[<currentTiddler>has:field[your-field-name]">
    <$view field="your-field-name"/>
  </$list>
  <!-- If your field doesn't exist, then display default tiddler title -->
  <$list filter="[<currentTiddler>!has:field[your-field-name]">
    <$view field="title"/>
  </$list>
</h2>

This is the technique I used to display alternate titles.

As a disclaimer, it is not recommended to modify core tiddlers, like I have here, as it might be missed in an upgrade.

You can implement @RedAsset’s method without over writting core tiddlers now using the "View Template Title cascade.

Just ask if you want to know how to do this.

@JanJo, looking at some documentation for Alias ViewTemplate (Using Matt Lauber's Aliases plugin and displaying aliases as part of the current tiddler), I think this very cool, and will use it, but it doesn’t solve this problem.

What I want to do is link to an article titled Egya Dara, but have that link read as Duke Egya, but I don’t want to put

[[Duke Egya|Egya Dara]]

I have found a way to do it but I have to put this:

<$link to=“Egya Dara”><$view tiddler=“Egya Dara” field=“nameTitle”><$view tiddler=“Egya Dara” field=“title”/></$view></$link>

His title may change. He may one day become a King. On his entry, there is a field with Duke Egya in it.

I think @RedAsset has the method that I want. Is there something already built that does that or is my <$link><$view><$view> nest the best? @TW_Tones?

You might want to try a filter with the addprefix operator.

<$list filter="[[Egya Dara]addprefix[ ]addprefix[nameTitle]]"/>

Note: you would have to use the addprefix operator twice to add a space between the titleName and title. Maybe someone else has a method without adding the extra addprefix operator in there or you can add a space at the end of the titleName field, for example, your field might look like this:

titleName: "Duke "

You can ignore my last suggestion. I have come up with a better one for you.

First, download and import this macro to your TiddlyWiki: $__macros_title-link.js.json (994 Bytes).

Then refresh your TiddlyWiki.

After importing the macro, simply use this code:

<<link "Egya Dara">>

This will work with whatever tiddler title you put in there as long as the tiddler has the field called titleName, otherwise it will output just the tiddler title in a link.

The source code of that file looks like this:

/*\
title: $:/macros/title-link.js
type: application/javascript
\*/
(function() {

    /*jslint node: true, browser: true */
    /*global $tw: false */
    "use strict";

    exports.name = "link";

    exports.params = [{
            name: "link"
        },
    ];

    /*
    Run the macro. Make sure it accepts the parameters you have defined above.
    */
    exports.run = function(link) {
        try {
            return "<$link to='"+link+"'><$list filter='[["+link+"]has:field[titleName]]' variable='tiddler-title'><$view tiddler=<<tiddler-title>> field='titleName'/> </$list><$view tiddler='"+link+"' field='title'/></$link>";
        } catch (err) {
            console.error(err.stack)
            return "(ERROR: " + err.message + ") ";
        }
    };

})();

If you are going to copy/paste that, make sure you have type set to application/javascript and a field called module-type and set that to macro. Name the macro tiddler whatever you want.

As @TW_Tones wrote: This is a job for …

Actually this thread has given rise to a little more reflection on the subject of alternative titles. While we do have various ways to handle them including macros, plugins and even bespoke JS I do think it is such a fundamental need it deserves some research and refining.

I do favor the use of filters in “filtered transclusions” {{{ filter }}} if they are easy to read, but if you want to use the same result multiple times t can be used to set a variable.

  • However “filtered transclusions” often need <$text text={{{ filter }}}/> to stop them making links, I wish there was a symbolic way to invoke the text widget (and wikify widget)

Remember the following when seeking an alternative title;

  • You may still need to retain the original title as it is the key to the tiddler by which all other tiddler info can be retrieved.
  • Use the alternative title if it has a value otherwise the tiddler title
  • In some cases Use the alternative title if it has a value otherwise nothing
  • Use the first available title in a series of possible titles from fields or variables.

I will come back when I have something more helpful

Bespoke macro for me? Wow, thank you @RedAsset. I appreciate it.

@TW_Tones and @JanJo, I didn’t quite understand the uni-link plugin, but I got it working, and it works. I was thrown by the alias functionality. The uni-link plugin seems to do two things, and I only needed the one.

A post was split to a new topic: Possibility to improve the uni-link plugin

I just thought I would point out the 5.3.x “functions” which are filters now allow us to take a filter and generate a result without needing to wrap the result in a text widget to avoid linkification.

  • Just define a function and use it as if it was a variable name in your wikitext.
  • It will return the first value only so if you are generating a string such as a tooltip include a +[join[ ]] in your filter, or if you want a list of titles, use [+format:titlelist[]+join[]]

If you want the result of a filter, or a string to be passed as an attribute value, also look at the new backtick method Substituted Attribute Values

[Meta] Is there a way to update a thread but stop it rising to the top?

  • That would be good for cases like this where you want to update a past thread without bringing to everyone’s attention.