If I may restate your problem, staying away from code before I respond, because @telumire has answered your question based on the code you presented but presenting code is always a double edge sword because it can distract.
Problem restated
I want to pass a “title” into a string/or sentence and if present also display a hyphen ! Some random title [- $t$]
[if title not blank]
Rephrasing this I see all you want is a conditional hyphen
\define title(title)
@@text-align: center;
! Some random title {{{ [[$title$]!is[blank]then[-]] }}} $title$
@@
\end
<<title "Tony" >>
- however to avoid a link you need
<$text text={{{ [[$title$]!is[blank]then[-]] }}}/>
to replace the hyphen.
Other notes;
- Would you believe I never use the set widgets filter and value parameter at the same time? In fact the documentation implies it is incorrect to use both
- value The value to assign to the variable if the
filter
attribute is missing or not empty
- If it were not for the alignment we would not use a macro at all
- Especially in examples to share be a little more generous in your parameter naming eg not “t” but “title”.
Even now I see my response was unnecessarily influenced by your code because we could do this (place “style” section in a stylesheet tiddler)
<style>
.centred {
text-align: center;
}
</style>
<$let title="Tony">
!.centred Some random title <$text text={{{ [<title>!is[blank]addprefix[- ]] }}}/>
</$let>
- Here I assume the title is available in a variable so set it with the let widget for this example.
- I have long complained that we should not need to use such a verbose text widget in these cases but have a simple wikitext way to force it to text.
Lets digress;
Here is a work around for making the text widget hidden
Create a tiddler called text-only containing
<$text text=<<currentTiddler>>/>
Now introduce it in the filtered transclusion, rather than use the textwidget in the wiki text.
!.centred-title Some random title {{{ [<title>!is[blank]addprefix[- ]]||text-only }}}
So then I digress further, if we are transcluding lets go further;
Create a tiddler called hyphen-title containing
<$text text={{{ [<currentTiddler>!is[blank]addprefix[- ]]}}}/>
So back in our wiki text we can just use;
!.centred-title Some random title {{{ [<title>] ||hyphen-title }}}
- notice how I convert
<<title>>
to a filter [<title>]
but other forms are also valid [[$title$]]
As soon as you are going to do something more than once consider “modularising it” as I have with a transclude template, then generalise it so you can use it in even more cases;
- You could in fact move everything into a transclusion if you needed to do it many times.
Happy tiddlywiki play, the font of eternal tinkering.