Creating new tiddlers

436 views
Skip to first unread message

David Shaw

unread,
Jul 17, 2007, 4:29:49 PM7/17/07
to TiddlyWiki
I'm trying to create a button that, when clicked, will create a new
tiddler. This new tiddler will be a formTiddler, using Udo's plugin.
Now, I know I can use <<newTiddlerWithForm...>> and this works OK,
except that it won't let me set tags on the new tiddler, which I want
to do.

So, I've tried using plain old <<newTiddler...> with the syntax

<<newTiddler template:ViewTemplate text:"<<formTiddler
[[StorylineTemplate]]>>" tag:storyline>>

*but* this takes the closing >> in the quoted text as the closing >>
for the newTiddler macro, meaning that the button appears, followed by
'" tag:storyline>>' and it doesn't work. Also, this method cannot be
used to prompt for a tiddler title, the way that newTiddlerWithForm
does.

So, how do I create a new tiddler, with the desired body text and tags
*and* prompt the user for a title for that tiddler?

Many thanks in advance,

David Shaw

FND

unread,
Jul 17, 2007, 5:08:30 PM7/17/07
to Tiddl...@googlegroups.com
> So, how do I create a new tiddler, with the desired body text and tags
> *and* prompt the user for a title for that tiddler?

Let me start with a quick note:
The NewTiddler macro's "template" parameter might be confusing, as it
refers to a ViewTemplate, not a template in the transclusion[1] sense
(as used by the MediaWiki engine, for example).

Transclusion is achieved with the NewTiddler macro.
Take a look at this:
http://www.tiddlywiki.org/wiki/Preloading
If you have a tiddler with the desired formTiddler macro, you could
transclude that into your newly-created tiddler, circumventing the issue
of embedded "<<" and ">>" chars.

That leaves us with the prompt; for that, you will need a tiny bit of
embedded JavaScript code. But there's an issue with that:

Theoretically, resulting button would be created with something like the
following macro code:
<<newTiddler label:"new record"
title:{{prompt("Please enter a title.");}}
text:{{store.getTiddlerText("foo")}}
tag:"bar">>
(Note: "foo" and "bar" are to be replaced by the tiddler and tag of your
choice. Also, while this has not been extensively tested, I guess it
*should* work... )

However, with that code, the prompt will not appear when pressing the
macro button, but rather when the respective tiddler is opened.
There's probably a solution to that - most likely involving Eric's
InlineJavascriptPlugin[2] - but I'm afraid don't have one to offer
right now...

HTH.


-- F.


[1] Transclusion, here, means including the contents of one tiddler in
another tiddler; cf. http://en.wikipedia.org/wiki/Transclusion

[2] http://www.tiddlytools.com/#InlineJavascriptPlugin

David Shaw

unread,
Jul 17, 2007, 6:29:00 PM7/17/07
to Tiddl...@googlegroups.com
FND wrote:
>> So, how do I create a new tiddler, with the desired body text and tags
>> *and* prompt the user for a title for that tiddler?
>>
>
> Theoretically, resulting button would be created with something like the
> following macro code:
> <<newTiddler label:"new record"
> title:{{prompt("Please enter a title.");}}
> text:{{store.getTiddlerText("foo")}}
> tag:"bar">>
>
> However, with that code, the prompt will not appear when pressing the
> macro button, but rather when the respective tiddler is opened.
> There's probably a solution to that - most likely involving Eric's
> InlineJavascriptPlugin[2] - but I'm afraid don't have one to offer
> right now...
>
> HTH

Many thanks for your quick response - unfortunately, I cannot get it to
work as I want :-(

I don't want the tiddler to appear in edit mode - rather, I want it to
appear in view mode, so that the form appears, ready for people to edit
the form, rather than the tiddler (does that make sense?), so I tried
the following as the template for a FormTiddler

<html>
<sub><b>Title:</b></sub><br/><input name=title type=text/>
</html>
<<newTiddler label:"Create new storyline"
template:ViewTemplate
title:{{store.getTiddler("Storylines").data("title")}}
text:{{store.getTiddlerText("StoryTemplate")}}
tag:"storyline">>

but when I click on the button, it just gives me a tiddler with 'The
tiddler (title) doesn't yet exist' *and* the title won't actually
initialise until the second click of the button - *and* I need to close
down the tiddler and reopen it if I want to change the title to create
another new tiddler.

Anyway, thank you for your help - I guess I shall just have to file yet
another problem in the 'when I know enough JavaScript' category :-)

David Shaw

Saq Imtiaz

unread,
Jul 17, 2007, 7:02:06 PM7/17/07
to Tiddl...@googlegroups.com
Hey David,

Try the attached file. It is a quick five minute job and I am half asleep so don't expect far too much! I'll have another look in the morning.

Cheers,
Saq
--
TiddlyThemes.com ( http://tiddlythemes.com ) : a gallery of TiddlyWiki themes.
TiddlySnip ( http://tiddlysnip.com ) : a firefox extension that turns TiddlyWiki into a scrapbook!
LewcidTW ( http://tw.lewcid.org ) : a repository of extensions for TiddlyWiki
NewSavedTiddler.js

Saq Imtiaz

unread,
Jul 17, 2007, 7:09:27 PM7/17/07
to Tiddl...@googlegroups.com
Updated to warn if overwriting a tiddler.
NewSavedTiddler.js

David Shaw

unread,
Jul 18, 2007, 3:56:19 AM7/18/07
to Tiddl...@googlegroups.com
I could get to dislike you ;-)

Many, many thanks, Saq - that does the job beautifully :-)

David

Saq Imtiaz

unread,
Jul 18, 2007, 4:06:04 AM7/18/07
to Tiddl...@googlegroups.com
Very welcome. Let me know if it doesnt do anything you need.

On 7/18/07, David Shaw <tihn...@googlemail.com > wrote:
Reply all
Reply to author
Forward
0 new messages