How to create a tiddler to create a new tiddler with a customize name?

Hi everyone!
I’m trying to create a Tiddler thats alows me to create a new tiddler with the name customize and open it directly. My code only create the tiddler but with a default name and not the name that i introducing in a edit-text input box.
Anyone have any idea how to solve that? I paste here the code that i using it.

<!-- Campo para introducir el título del nuevo tiddler -->
Introduce un título:
<$edit-text tiddler="$:/temp/new-tiddler-title" field="text" tag="input" class="tc-edit-textinput"/>

<!-- Botón para crear el tiddler con ese nombre -->
<$set name="newTitle" filter="[<{$:/temp/new-tiddler-title}>get[text]]">
  <$button>
    Crear nuevo tiddler
    <$action-createtiddler
      title=<<newTitle>>
      text="Este es un tiddler con etiqueta"
    />
    <$action-navigate $to=<<newTitle>>/>
  </$button>
</$set>

I’using windows, with google chrome and the last version of TiddlyWiki, 5.3.7
Thanks in advance
Rosi

1 Like

Try this:

<$set name="newTitle" value={{$:/temp/new-tiddler-title}}>

Note that if you want to use a filter, you would write:

<$set name="newTitle" filter="[[$:/temp/new-tiddler-title]get[text]]">

enjoy,
-e

Hi Rosi, Welcome to the club!

If you want to have access to the text-field of a tiddler you can use the transclusion shortcut. eg:

title={{$:/temp/new-tiddler-title}}

I did rewrite your code a bit. The TW message tm-new-tiddler does create a new tiddler and it does navigate to it in edit-mode.

If the tiddler already exists, we only want to navigate to it. So I did use a conditional syntax.

Using actions with buttons, the best practice is to use the button actions parameter.

I did create a newTiddlerActions() procedure that can be connected to the button-widget actions parameter

The if condition <% if [{$:/temp/new-tiddler-title}has[text]] %> reads the content of the temp tiddler and checks if that tiddler has a text field.

  • If the tiddler exists and there is some text in the text field it is used to navigate to the tiddler
  • If the new tiddler title does not exist it has not text field, so the %else% path is used to create one using action-sendmessage

I used action-sendmessage, because tm-new-tiddler does create a new tiddler and also navigates to it using edit mode.

If you want to create new tiddlers using action-create tiddler, that are a lot of examples at: https://tiddlywiki.com/#ActionCreateTiddlerWidget, which you can play with.

\procedure newTiddlerActions()
<% if [{$:/temp/new-tiddler-title}has[text]] %>
  <$action-navigate $to={{$:/temp/new-tiddler-title}}/>
<%else%>
  <$action-sendmessage $message="tm-new-tiddler"
    title={{$:/temp/new-tiddler-title}}
    tags="OneTag [[Another Tag]]"
    text="Este es un tiddler con etiqueta"
  />
<%endif%>
\end

<!-- Campo para introducir el título del nuevo tiddler -->
Introduce un título:
<$edit-text tiddler="$:/temp/new-tiddler-title" field="text" tag="input" class="tc-edit-textinput"/>

<!-- Botón para crear el tiddler con ese nombre -->
<$button actions=<<newTiddlerActions>> >
  Crear nuevo tiddler
</$button>

@Rosi – I (as an admin) did modify your code block a bit, to make it readable.

Have a closer look at the following link, to see, how code blocks can be used here in the forum software.

Thanks so much. I am new here and also quite new with TiddlyWiki, so every input, it’s very welcome.

2 Likes

Uooaa!! Thanks so much for the improvement in the code. It works perfectly.
I’m quite new with tiddlywiki and I didn’t realy understand how it work with the procedure. The code of the newTiddlerActions() is all this text?

<% if [{$:/temp/new-tiddler-title}has[text]] %>
  <$action-navigate $to={{$:/temp/new-tiddler-title}}/>
<%else%>
  <$action-sendmessage $message="tm-new-tiddler"
    title={{$:/temp/new-tiddler-title}}
    tags="OneTag [[Another Tag]]"
    text="Este es un tiddler con etiqueta"
  />
<%endif%>
\end

Thanks a lot!!

yes - A procedures starts with the \procedure name() and ends with \end or \end name
Please read this: Create Code-Blocks Using Backticks in Discourse Threads

Your code also works if you add Eric’s fixes to the filter syntax and use $basetitle instead of title for the actions-createtiddler parameters

See:

  • <$set name="newTitle" filter="[[$:/temp/new-tiddler-title]get[text]]"> and
  • $basetitle=<<newTitle>
  • <$action-navigate $to=<<createTiddler-title>>/>

in the code below.

So you have been close :wink:

The behaviour is a bit different than mine, since action-createtiddler creates a lot of new tiddlers with uniqe names. So action-navigate also has to be adjusted using createTiddler-title variable. And it has to be moved inside the action-createtiddler body.

<!-- Campo para introducir el título del nuevo tiddler -->
Introduce un título:
<$edit-text tiddler="$:/temp/new-tiddler-title" field="text" tag="input" class="tc-edit-textinput"/>

<!-- Botón para crear el tiddler con ese nombre -->
<$set name="newTitle" filter="[[$:/temp/new-tiddler-title]get[text]]">
  <$button>
    Crear nuevo tiddler
    <$action-createtiddler
      $basetitle=<<newTitle>>
      text="Este es un tiddler con etiqueta"
    >
      <$action-navigate $to=<<createTiddler-title>>/>
    </$action-createtiddler>
  </$button>
</$set>

have fun!
-mario

Yes, it’s working with your modifications. Only thing I get Tiddler’s name in double [[RosiTiddler]]. And I get a message that i shouldn’t use [ in Tiddler’s title. Do you know why is that?

If you create tiddler titles with your mechanism, there should be no square brackets. I do not understand where this could come from.


I did fined an other thing. We should use the trim[] operator, to avoid leading or trailing spaces in tiddler titles.

With your code:

<$set name="newTitle" filter="[[$:/temp/new-tiddler-title]trim[]get[text]]">

My new code would look as follows, which may be a bit overwhelming.

I did add 2 new functions.

  • f.tempTiddler() $:/temp/new-tiddler-title … This one is convenient, since we can now change the temp tiddler title globally.
  • f.newTitle() [<f.tempTiddler>get[text]trim[]] … is a function, that reads the content of f.tempTiddler and trims leading an trailing whitespace. Tiddlers with leading and trailing whitespace can cause problems. So we should avoid them. The trim[] takes care of this one.

Functions can be used like variables. So the <% if condition has been change dto use f.newTitle. <$action-navigate and <$action-sendmessage also use f.newTitle now. So all of them should get the new trimmed title.

<$edit-text … uses <<f.tempTiddler>> now

\function f.tempTiddler() $:/temp/new-tiddler-title
\function f.newTitle() [<f.tempTiddler>get[text]trim[]]

\procedure newTiddlerActions()
<% if [<f.newTitle>has[text]] %>
  <$action-navigate $to=<<f.newTitle>>/>
<%else%>
  <$action-sendmessage $message="tm-new-tiddler"
    title=<<f.newTitle>>
    tags="OneTag [[Another Tag]]"
    text="Este es un tiddler con etiqueta"
  />
<%endif%>
\end

<!-- Campo para introducir el título del nuevo tiddler -->
Introduce un título:
<$edit-text tiddler=<<f.tempTiddler>> field="text" tag="input" class="tc-edit-textinput"/>

<!-- Botón para crear el tiddler con ese nombre -->
<$button actions=<<newTiddlerActions>> >
  Crear nuevo tiddler
</$button>

Hope that’s not too confusing. If it is, just ask.
-mario

Interesting!! I didn’t know about functions.
I will look at that tomorrow, my brain need a break :sweat_smile:
I’ll be back tomorrow with more questions. Sorry! I’m just a beginner.
Thanks so much for the pacience.
Rosi

1 Like

Hello.
I’m using this code to create tiddlers from an edit text field:

\define DocumentCreate()
<$action-createtiddler $basetitle={{$:/temp/Documentedit}} tags="Document Walsall" $template="$:/ReE/Projects/Template_Document"/>
\end

Add new document: <$edit-text tiddler="$:/temp/Documentedit" tag="input" type="text" default="Document Title"/> <$button actions=<<DocumentCreate>> >
{{$:/images/fa5/solid/file-signature}}
</$button>

Thanks Mario.
I’ve implemented your code and added some dropdown boxes to tag the new tiddler. With one tag it works perfectly but if i want to insert two different tags, it doesn’t work. Do you know what it’s wrong in my syntax?

\function f.tempTiddler() $:/temp/new-tiddler-title
\function f.newTitle() [<f.tempTiddler>get[text]trim[]]

\procedure newTiddlerActions()
<% if [<f.newTitle>has[text]] %>
  <$action-navigate $to=<<f.newTitle>>/>
<%else%>
  <$action-sendmessage $message="tm-new-tiddler"
    title=<<f.newTitle>>
    tags={{$:/temp/new-tiddler-tag}} {{$:/temp/new-tiddler-tag-domain}} 
    text="Este es un tiddler con etiqueta"
  />     
  <$action-setfield $tiddler="$:/temp/new-tiddler-title" text=""/>  <!--Limpia el título del tiddler-->
  <$action-setfield $tiddler="$:/temp/new-tiddler-tag" text=""/> <!--Limpia los tags de objeto-->
  <$action-setfield $tiddler="$:/temp/new-tiddler-tag-domain" text=""/> <!--Limpia los tags de dominio-->

<%endif%>
\end


<!-- Campo para introducir el título del nuevo tiddler -->
1. Introduce un título:<br>

<$edit-text tiddler="$:/temp/new-tiddler-title" field="text" tag="input" class="tc-edit-textinput"/>

<!-- Dropdown para seleccionar una etiqueta sobre el tipo de OBJETO-->
2. Elige una de las etiquetas del menú desplegable. <br>
<$select tiddler="$:/temp/new-tiddler-tag" field="text">
  <option value="">Selecciona una etiqueta</option>
  <option value="Costs">Costs</option>
  <option value="Issues">Issues</option>
  <option value="Parameter">Parameter</option>
  <option value="Community">Community</option>
</$select>

<!-- Dropdown para seleccionar una etiqueta sobre el tipo de DOMINIO -->
Elige un tipo de DOMINIO: 
<$select tiddler="$:/temp/new-tiddler-tag-domain" field="text">
  <option value="">Selecciona una etiqueta</option>
  <option value="Regulation">Regulation</option>
  <option value="Envi.& Nature">Nature</option>
  <option value="Wellness">Wellness</option>
  <option value="Water">Water</option>
</$select>

<!-- Botón para crear el tiddler con ese nombre -->
3. Presiona el botón "Crear nuevo tiddler" <br>
<$button actions=<<newTiddlerActions>> >
  Crear nuevo tiddler
</$button>

Thanks in advance,
Rosi

This will need quotes:

Perhaps like this:

    tags="{{$:/temp/new-tiddler-tag}} {{$:/temp/new-tiddler-tag-domain}}"

Unquoted attribute values cannot contain spaces.

It might be better to also capture potential spaces within your fields, with something like this (untested):

    tags={{{ [{$:/temp/new-tiddler-tag}] [{$:/temp/new-tiddler-tag-domain}]  :map[format:title list[]]  +[join[ ]] }}}

Thanks Scott,
I’ve already tried that, but with quotes takes as a tag the full text ( $:/temp/new-tiddler-tag) and not the text that is in the temp tiddler (water or costs).

Change to:

tags={{{ [{$:/temp/new-tiddler-tag}] [{$:/temp/new-tiddler-tag-domain}]
         +[format:titlelist[]join[ ]] }}} 

Notes:

  • Retrieve both values and join them together into a single text value that is assigned to the tags field.
  • +[format:titlelist[]join[ ]] ensures that if an individual tag value contains spaces, it is enclosed in doubled square brackets and then all the values are joined to create a space-separated list

enjoy,
-e

1 Like

Thanks so much Eric!!
It works perfectly.
Rosi

1 Like

Oops, sent before complete. Updated… only to find Eric had beat me to it.

As usual.

1 Like

Long post warning :wink:

It is very common to extend some wikitext code, once it works. As you can see, there are some elements, that are duplicated, or the code used is very similar. Eg:

  • The $:/temp/new-** tiddler titles. They are duplicated a lot.

  • The action-setfield code-block stands out there are only tiny differences, but a lot to type.

  <$action-setfield $tiddler="$:/temp/new-tiddler-title" text=""/>  <!--Limpia el título del tiddler-->
  <$action-setfield $tiddler="$:/temp/new-tiddler-tag" text=""/> <!--Limpia los tags de objeto-->
  <$action-setfield $tiddler="$:/temp/new-tiddler-tag-domain" text=""/> <!--Limpia los tags de dominio-->

IMO it would be much nicer, if we could have 1 command, instead of 3.

  • In TW we call variables, that have the following structure: $:/temp/something namespace variables.
  • So all variables, which start with $:/temp/ are part of the “temp namespace”.
  • If I want to list in Advanced Search → Filter tab, I can use a filter like this: [prefix[$:/temp/]]

So I could delete all temporary tiddlers with:

  • <$action-deletetiddler $filter="[prefix[$:/temp/]]"/>

The problem with that delete function is, that it deletes every temporary tiddler in the system → That’s not what we need.

So should make the namespace more specific. eg: $:/temp/rosi/ – So we only delete “Rosi’s” temp tiddlers. I did do exactly that in the following code rewrite.

To do that I did define some more “tiddler title” functions.

  • Temp tiddlers get a /rosi/ namespace
  • The “tag” tag and the “domain” tag have new functions now

Wo we can easily rename them in the future if we need to. eg. If we need a different namespace.

<!-- Define temporary tiddler titles -->
\function f.tempTiddler() $:/temp/rosi/new-tiddler-title

\function f.tempTag()     $:/temp/rosi/new-tiddler-tag
\function f.tempDomain()  $:/temp/rosi/new-tiddler-domain

We already know the following code, but I did add a bit more comments, to make it clearer, what it does and why.

<!-- Function to "get" a whitespace trimmed new tiddler title. 
  Trimming whitespace here is important, since users can enter the new title.
  If they accidentally use a leading or trailins space, that can cause problems.
--> 
\function f.getNewTitle() [<f.tempTiddler>get[text]trim[]]

In the OP you wrote, that you had a problem with “combining” tags. Eric already posted a fix for that one. I did use a new function. I named it: f.getTags – See the plural. It returns a tag-string, that can be used like that: tags=<<f.getTags>>, which imo is much easier to read then a long filter string using all the $:/temp/... variable.

New code to <<f.getTags>>

<!-- Function to "get" multiple tags and format them as a titlelist
  titlelist see: https://tiddlywiki.com/#format%20Operator
--> 
\function f.getTags() [<f.tempTag>get[text]] [<f.tempDomain>get[text]] +[format:titlelist[]join[ ]]

I did also extend the dropdowns a little bit. They got several new elements, so it looks like this:

  • Description which is a disabled option
  • An “-none-” option, which is use to define an empty string “”
    • You will need to translate this one into Spanish
  • The select-widget got a default="" parameter.
    • <$select tiddler=<<f.tempTag>> field="text" default="">
    • Also see the <<f.tempTag>> function name

So the first select looks as follows:

<!-- Dropdown para seleccionar una etiqueta sobre el tipo de OBJETO-->
2. Elige una de las etiquetas del menú desplegable. <br>
<$select tiddler=<<f.tempTag>> field="text" default="">
  <option disabled>Selecciona una etiqueta</option>
  <option value="">-none-</option>
  <option value="Costs">Costs</option>
  <option value="Issues">Issues</option>
  <option value="Parameter">Parameter</option>
  <option value="Community">Community</option>
</$select>

The full code

Which is tested and seems to work for me.

<!-- Define temporary tiddler titles -->
\function f.tempTiddler() $:/temp/rosi/new-tiddler-title

\function f.tempTag()     $:/temp/rosi/new-tiddler-tag
\function f.tempDomain()  $:/temp/rosi/new-tiddler-domain

<!-- Function to "get" a whitespace trimmed new tiddler title. 
  Trimming whitespace here is important, since users can enter the new title.
  If they accidentally use a leading or trailins space, that can cause problems.
--> 
\function f.getNewTitle() [<f.tempTiddler>get[text]trim[]]

<!-- Function to "get" multiple tags and format them as a titlelist
  titlelist see: https://tiddlywiki.com/#format%20Operator
--> 
\function f.getTags() [<f.tempTag>get[text]] [<f.tempDomain>get[text]] +[format:titlelist[]join[ ]]

<!-- Helper procedures -->
\procedure deleteTempTiddlers()
<$action-deletetiddler $filter="[prefix[$:/temp/rosi/]]" />
\end

\procedure newTiddlerActions()
<% if [<f.getNewTitle>has[text]] %>
  <$action-navigate $to=<<f.getNewTitle>>/>
<%else%>
  <$action-sendmessage $message="tm-new-tiddler"
    title=<<f.getNewTitle>>
    tags=<<f.getTags>> 
    text="Este es un tiddler con etiqueta"
  />
  <!-- delete all temporary tiddlers -->
  <<deleteTempTiddlers>>

<%endif%>
\end


<!-- Campo para introducir el título del nuevo tiddler -->
1. Introduce un título:<br>

<$edit-text tiddler=<<f.tempTiddler>> field="text" tag="input" class="tc-edit-textinput"/>

<!-- Dropdown para seleccionar una etiqueta sobre el tipo de OBJETO-->
2. Elige una de las etiquetas del menú desplegable. <br>
<$select tiddler=<<f.tempTag>> field="text" default="">
  <option disabled>Selecciona una etiqueta</option>
  <option value="">-none-</option>
  <option value="Costs">Costs</option>
  <option value="Issues">Issues</option>
  <option value="Parameter">Parameter</option>
  <option value="Community">Community</option>
</$select>

<!-- Dropdown para seleccionar una etiqueta sobre el tipo de DOMINIO -->
Elige un tipo de DOMINIO: 
<$select tiddler=<<f.tempDomain>> field="text"  default="">
  <option disabled>Selecciona una etiqueta</option>
  <option value="">-none-</option>
  <option value="Regulation">Regulation</option>
  <option value="Envi.& Nature">Nature</option>
  <option value="Wellness">Wellness</option>
  <option value="Water">Water</option>
</$select>

<!-- Botón para crear el tiddler con ese nombre -->
3. Presiona el botón "Crear nuevo tiddler" <br>
<$button actions=<<newTiddlerActions>> >
  Crear nuevo tiddler
</$button>

Which looks like this:

have fun!
Mario

1 Like

I really appreciate your suggestions and lessons. I’m learning a lot. Thanks a lot!!
Could I ask you one more thing? It would be possible to make that when the new tiddler created opens it do not open in the edit mode but in the view mode?
Thanks so much
Rosi