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.
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.
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:
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.
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.
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.