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