new tiddler from template that has placeholders in it

130 views
Skip to first unread message

Dave Parker

unread,
Mar 19, 2011, 7:58:50 PM3/19/11
to TiddlyWiki
Hi,

I'd like to be able to make a new tiddler based on a template tiddler
and replace the placeholders in that template tiddler with the new
tiddler's title.

something like this:

<<newTiddler
tag:"ProblemsList"
label:"add problem"
title:"input short description of problem here"
text:{{store.getTiddlerText("ProblemTemplate")}} (pseudocode: with:
{{tiddler.title}})
>>


originally I had the tiddler "ProblemTemplate" with this in it
<<tiddler ProblemTemplate5 with: {{tiddler.title}}>>

and it kind of worked, except you can't view the contents in a popup.
I need the new tiddler to have "real" content, instead of transcluded.


Any ideas?

Dave

Dave Parker

unread,
Mar 23, 2011, 11:46:11 PM3/23/11
to TiddlyWiki
I found Udo's TiddlersWithParams from here
http://tiddlywiki.abego-software.de/#TiddlerWithParamsPlugin
that sounds like it would have done this, but it doesn't work in the
recent TW version.

Has anyone found a replacement method that does the same thing these
days?

Dave Parker

unread,
Mar 23, 2011, 11:58:43 PM3/23/11
to TiddlyWiki
nevermind, that wouldn't have worked either - it seems to be for
viewing tiddlers, not making them

PMario

unread,
Mar 24, 2011, 9:12:14 AM3/24/11
to TiddlyWiki
Hi Dave,

Reading you code, it is very hard, to guess, what you want.

I think it would be easier, if you discribe you problem in prose.

-m

whatever

unread,
Mar 24, 2011, 9:44:08 AM3/24/11
to TiddlyWiki
Try

<script label="input short description of problem here" title="input
short description of problem here">
var alwaysTag="ProblemsList";
var p1=prompt("Problem name","");
if(!p1)return;
if(store.tiddlerExists(p1)) {
if(!
confirm(config.messages.overwriteWarning.format([p1.toString()])))
return null;}
var tags=(alwaysTag);
var title=(p1);
store.saveTiddler(
title,
title,
store.getTiddlerText('ProblemTemplate').replace(/PLACEHOLDER/g, p1),
config.options.txtUserName,
new Date(),
tags);
autoSaveChanges(null,[tiddler]);
story.displayTiddler(null,title);
</script>

I'm guessing that in your ProblemTemplate, you probably use $1 as a
placeholder. The replace function didn't work for me in that case, so
I suggest you replace $1 with PLACEHOLDER (or some other word). I
tried and it worked.

If you use the default theme, add the following to the stylesheet to
make the link look like button:
/*Script Buttons*/
.scriptbutton a {color:[[ColorPalette::PrimaryDark]]; border:1px solid
[[ColorPalette::SecondaryMid]]; font-weight:normal; margin:2px;
padding:0px 3px;}
.scriptbutton a:hover {color:[[ColorPalette::PrimaryDark]]; background:
[[ColorPalette::SecondaryLight]]; border-color:
[[ColorPalette::SecondaryMid]]; font-weight:normal; margin:2px;
padding:0px 3px;}
.scriptbutton a:active {color:[[ColorPalette::Background]]; background:
[[ColorPalette::SecondaryMid]]; border:1px solid
[[ColorPalette::SecondaryDark]]; font-weight:normal; margin:2px;
padding:0px 3px;}

You can use it like this:
{{scriptbutton{
<script ...>
THE ABOVE SCRIPT
</script>
}}}

w

Dave Parker

unread,
Mar 24, 2011, 9:55:05 AM3/24/11
to TiddlyWiki
Thats it! Thank you w! (and thanks for replying PMario)

I had a template with stuff like this
<<select [[location@here]] rows:1 allowBlank
+BodyLocationTemplateTotal allowEdit>> which worked fine except for
when viewed through a transclusion, and now I just replace the word
"here". Works great.
Reply all
Reply to author
Forward
0 new messages