Macros, templates - best practices?

37 views
Skip to first unread message

mjl1966

unread,
Feb 10, 2012, 8:22:24 PM2/10/12
to TiddlyWikiDev
I've read a lot of the material on macros and have more questions than
answers. I'm sure these topics have been talked to death, but 688
search results is a lot of parsing. So....

First, it seems to me that being able to create a macro is useless
unless you can have a new tiddler populated with macro entries. i.e.
- who's going to write macros for one tiddler? Thus, there must be
some way to invoke a tiddler with more than just the newTiddler macro
arguments. Otherwise all the other macros would be pretty useless.

My question is the same one that has bee asked for years now: How do I
invoke a tiddler populated with text, controls, etc? Hopefully there
is a generally recognized standard for this?

Thanks.

-MJL

PMario

unread,
Feb 11, 2012, 9:12:50 AM2/11/12
to TiddlyWikiDev
There are 3 ways I prefer to use macros.

1) A macro call is part of the tiddler text
eg: <<list filter [tag[myTag]]>>
which will create a "dynamically" updated list of tiddlers, that are
tagged myTag. So there is no need for the author, to create a new list
like
* tiddler 1
* tiddler 2 ...
everytime a new tiddler is tagged myTag. For a macro used in this way,
imo it makes no sense to populate a new tiddler with text. Since the
author needs to write the text.
You can have a look at my HelloWorld space to get some working
examples, for basic macro usage. [1]

2) most macros can be called within a Template eg: ViewTemplate,
EditTemplate, PageTemplate.
If you want to write a macro, that is part of every tiddler, you'd
better use this approach.
HelloWorldNamedParamsPlugin [2] documentation section describes, how
to use this macro with eg: ViewTemplate. Also have a look a the
Test... tiddlers.

3) Transcluding some "template text" into a new tiddler with the
<<tiddler xxx with: param1 >> macro. Where param1 can be evaluated
"code". (evaluated macro parameters are deactivated at TiddlySpace,
due to security restrictions)
see link [3] which opens 3 examples. There are backlinks to google
group discussions, that may contain some more info.
using <script label ...></script> you'll need InlineJavascriptPlugin
[4]

>My question is the same one that has bee asked for years now: How do I
>invoke a tiddler populated with text, controls, etc? Hopefully there
>is a generally recognized standard for this?

I hope the above 3 different workflows, will solve some of your
problems or at least give you some usefull hints :)

have fun!
-mario

[1] http://helloworld.tiddlyspace.com/#HelloWorldButtonPlugin
[2] http://helloworld.tiddlyspace.com/#HelloWorldNamedParamsPlugin

[3]
http://hoster.peermore.com/recipes/TeamWork/tiddlers.wiki#%5B%5BNewTiddler%20with%20prototype%20text%5D%5D%20%5B%5BNewTiddler%20with%20DateAndTime%5D%5D%20%5B%5BCreate%20New%20Tiddler%20with%20a%20transcluded%20script%5D%5D
[4] http://www.tiddlytools.com/#InlineJavascriptPlugin

Eric Shulman

unread,
Feb 11, 2012, 11:53:16 AM2/11/12
to TiddlyWikiDev

Hi MJL,

> My question is the same one that has bee asked for years now: How do I
> invoke a tiddler populated with text, controls, etc? Hopefully there
> is a generally recognized standard for this?

mario addressed the basics of macro invocation in his reply, so I'm
just going to respond to the specific question you asked - how to 'pre-
populate' tiddler content when creating a new tiddler (which, btw, has
been answered *many* times over the years...)

The <<newTiddler>> macro has optional parameters tht allow you to
define initial values for the title, tags, text and custom fields of a
tiddler. For your purposes, the parameter you want is "text:..."

<<newTiddler text:"this is the default text for the new tiddler">>

Unfortunately, the macro syntax is a bit restrictive when specifying
text: it must be enclosed in either single- or double-quotes (which
means you can't use BOTH within the text), and cannot contain TW
macros (the closing ">>" within the text would break the surrounding
macro definition!). Also, if the default text is lengthy (or multi-
line), it can become ridiculously difficult to read and understand the
nesting of syntax within the surrounding macro.

Fortunately, there is simple method of specifying the text that avoids
the ugliness: first store the desired default text in a separate
tiddler (e.g., [[SomeTiddler]]) and then retrieve that tiddler content
for use as the value of a macro param, by using the *evaluated
parameter* syntax to invoke the TWCore's store.getTiddlerText()
function, like this:

<<newTiddler text:{{store.getTiddlerText("SomeTiddler")}}>>

The result is that the contents of SomeTiddler are pre-loaded into the
text field of the new tiddler when it is initialized for editing.
QED.

enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios

----
WAS THIS ANSWER HELPFUL? IF SO, PLEASE MAKE A DONATION
http://www.TiddlyTools.com/#Donations
note: donations are directly used to pay for food, rent,
gas, net connection, etc., so please give generously and often!

Professional TiddlyWiki Consulting Services...
Analysis, Design, and Custom Solutions:
http://www.TiddlyTools.com/#Contact
Reply all
Reply to author
Forward
0 new messages