I am trying to create a script to create a new tiddler and set its title.
Script is in a tiddler called $:/TLS/Actions/Add New Link whose text field is
-----
<$button>
<$action-createtiddler
$basetitle="{{$:/TLS/linktitle}}"
tags="Links"
_canonical_uri = "Images/VisitorsBook.pdf"
type="application/pdf"
/>
<$action-setfield $tiddler="$:/TLS/incremental" text={{{ [{$:/TLS/incremental}add[1]] }}}/>
Add this link
</$button>
The tiddler $:/TLS/linktitle has the text field = CS{{$:/TLS/incremental}} which displays as CS1
When I click the button, I end up with a new tiddler whose title is {{$:/TLS/linktitle}} rather than its text value, CS1. The _canonical_uri field is set correctly and displays the linked PDF.
I have tried
removing the double quotes around the $basetitle value which ends with a new tiddler called CS{{$:/TLS/incremental}}
replacing the double quotes with <<$:/TLS/linktitle>> which ends up with a new tiddler called new tiddler
tried three {'s which did not work either
So now Iām stumped. What combination of brackets do I need to end up with a new tiddler titled CS1?
I think it is better to describe, what you try to achieve in plain text, than showing some code that does not do what you want.
The first thing is, that actions should always be outside the button body.
action-createtiddler does auto-increment the base title, if the tiddler does exist already.
The 3rd example at: https://tiddlywiki.com/#ActionCreateTiddlerWidget shows the following code. It uses the default New Tiddler title, and sets overwrite=yes. ⦠There are a lot of other examples. Playing with them will reveal how it works.
You do not need overwrite so you can remove it.
You see the the transclusion is not covered in quotes, so the content of the tiddler is used to define the $basetitle
If you do not like the space in the new titles, there is the unusedtitle-macro, which is very flexible with new name creation.
The unusedtitle example-code in the tiddlers also opens the Recent-tab in the right sidebar. ⦠That code should probably not be part of production code. Itās only there for testing.
My guess: The quotation marks do what theyāre supposed to, i.e they ensure their encapsulated value is literal. But you want it to be evaluated so just remove the quotation marks, i.e:
$basetitle={{$:/TLS/linktitle}}
Iām guessing you intended for the quotation marks to āensure encapsulationā so you donāt get $basetitle=foo bar (in which case only foo would become the basetitle and the bar would probably mess up the succeeding code) but my interpretation is that the {{}} by themselves āencapsulateā also itās evalutated output, so thereās no need for further encapsulation.
(Someone please correct me if Iām twaddling nonsense.)
Thank you for your email. Your comment about actions being outside buttons would appear to be misleading, as per example 1 of the action-createtiddler page ( https://tiddlywiki.com/static/ActionCreateTiddlerWidget.html). In this example the action is clearly within the button declaration. Also, the first para of the action tiddler page states ā Action widgets are used within triggering widgets such as the ButtonWidget.ā
As for removing the double quotes around the value of the basetitle attribute, I did that and as explained, it also did not work.
The problem seems to be transcluding a transclusion. This this case, the linktitle tiddler is a transclusion of the incremental tiddler. In this case, the basetitle attribute is transcluding the linktitle tiddler but it is not recognising that the linktitle tiddler involves a transclusion itself.
@twMat is spot on here, and in your adventure @Bob_Jansen to understanding quotes and braces there are a number of places where you need only use one form of āencapsulationā or delimiters such as in filters you may have an operator[literal] but then use a field reference operator{!!fieldname} or variable operator<varname> see how we abandon the [ ] brackets?.
It uses an extension of the methods used in most languages seen here Literal Attribute Values. As @twMat pointed out quotes are for literals.
What tends to dominate is tiddlywikis custom braces { [ <
Outside of filters they are doubles so as to not conflict with html {{ [[ << with the exception now of {{{ and newly introduced (inside backticks) $(varname)$ and ${ filter }$
As explained in my original post, I tried using just the transclusion syntax for the basetitle attribute value and it did mot work. I need the new tiddler to be called CS1 in this case and to increment the incremental tiddler so the next time the new tiddler would be called CS2. The incremental code works.
As I explained in my reply to PMario, the problem seems to me to be the transclusion of a transcluded tiddler is not working
It may not be perfect, but Iām sure it is better than the existing version. Since the first example is for advanced users, I did move it to the end. Now it starts with the more basic examples.
I think, documentation should move fast so it can be incrementally improved, when contributors have time.
Since I did not see a chance to get the PR merged and I did run out of time, I did close the PR.
I was happy to see this āunusedtitleā macro and I want to use it as an input to feed into <$action-createtiddler> it would be a nice add to have separator logic in that action widget. In the absence of that, whatās the best way to use a createtiddler with a different separator in the case that the basetitle is the result of a query? Iām stuck trying to get the logic of this one⦠Seems like wikify is neededā¦
I want my basetitle to be something like <<unusedtitle baseName:<<now "YYYY0MM0DD">> separator:"_">> which obviously wonāt work, need to get the macro in the macro into something I can put into the actionwidgetā¦
@stobot you are aware that if you provide a basetitle that already exists it will make it unique by appending a number as for regular new tiddlers? In this case you can use a filtered transclusion to define the name and let it handle clashes?
Yes, unfortunately thatās doing tiebreakers with the space character separator which Iām trying to avoid.
unusedtitle is a useful macro to change the separator but being a macro I canāt feed it a macro as a parameter (like <<now>>) unless I use the macrocall widget but then I canāt save that as a value to feed to createtiddler.
Thanks @TW_Tones, that block of code is what I was struggling to think of! Iāve realized that I could also make use of the counter functionality of <$list> to accomplish a no-space tiebreaker in my specific case but it was bugging me to not remember how to string the macros together (macro into a macro into a parameter).
I emphasise, there are a few areas in tiddlywiki which are tricky to wrap your head around, and even when you know them, if you are little tired, they can be hard to recall.
I really do think better solutions are available in 5.3.0 but an unused title operator may help.
But this still not solve our need to use a widget to get a value to give it to a parameter within a widget (except by wikifying at the last moment).
Still researching
[Edited]
As I suspected you can do it with the triple curly braces, ie a āfiltered transclusionā, or the new substitution method. In both cases the result should be returned without needing to wikify.
In this case I made my own unused title āfilterā but it could be made into a function.
Of course you can easily modify the function, even add parameters.
Here I solved the complexity with using a widget to provide an attribute value, but not using one, but building my own āunused titleā filter/function.
The Question remains what is the best way to use a widget to provide an attribute value?