named parameters for transclusion

9 views
Skip to first unread message

Michael Mahemoff

unread,
Nov 13, 2009, 7:25:04 PM11/13/09
to tiddly...@googlegroups.com
http://tiddlywiki.org/wiki/Transclusion

At present, transclusion only allows a list of parameters, which are
declared in the template as $1 to $9. I wonder if there are any plans
to (a) allow named parameters; and (b) support more than 9 parameters.

What I mean by named parameters is something like this:

"greeting" template tiddler:
hello "$name"

some other tiddler:
<<tiddler [[greeting]] name: joe>>

There are some efforts to replace jinja templating with
tiddlywiki-style templating, and likewise, I am doing some other work
with templating right now where it would make sense to use
tiddlywiki's formatter. It's not possible right now though as I would
need to use named parameters. (So I'm more interested in the library
than the macro above, per se.)

FND

unread,
Nov 14, 2009, 4:14:02 AM11/14/09
to tiddly...@googlegroups.com
> At present, transclusion only allows a list of parameters, which are
> declared in the template as $1 to $9. I wonder if there are any plans
> to (a) allow named parameters; and (b) support more than 9 parameters.

I don't think it's come up before, though it might be nice.
Having said that, it shouldn't be too hard to create a plugin (perhaps
using supplant*), which might eventually be integrated into the core.


-- F.


* http://javascript.crockford.com/remedial.html

Eric Shulman

unread,
Nov 14, 2009, 9:16:46 AM11/14/09
to TiddlyWikiDev
> > At present, transclusion only allows a list of parameters, which are
> > declared in the template as $1 to $9. I wonder if there are any plans
> > to (a) allow named parameters; and (b) support more than 9 parameters.
> I don't think it's come up before, though it might be nice.
> Having said that, it shouldn't be too hard to create a plugin (perhaps
> using supplant*), which might eventually be integrated into the core.

Jeremy and I discussed this a very long time ago, and I've actually
implemented something *like* this in several different plugins (but
not with the <<tiddler>> macro handler).

I also have an existing core tweak for the <<tiddler>> macro -- to fix
refresh handling for transclusions with params -- that could be
extended to add pre-processing for named params in addition to the
current $1 to $9 markers.

For each named param (e.g., "name:foo") passed in the macro, any
instances of "$name" in the target tiddler will be replaced with the
corresponding value. Note: occurrences of "$somename" within the
tiddler will be left unchanged if "somename" is *not* used as a param
in the tiddler macro.

Also, because of the manner in which parseParams() works, all
positional params must be specified either before or after any named
params (i.e., you can't mix named params in the middle of the
positional params). Thus:

<<tiddler SomeTiddler with: p1 p2 p3 name1:val name2:val>>
or
<<tiddler SomeTiddler name1:val name2:val with: p1 p2 p3>>
but *NOT*
<<tiddler SomeTiddler with: p1 name1:val name2:val p2 p3>>

-e

Michael Mahemoff

unread,
Nov 15, 2009, 1:27:47 PM11/15/09
to tiddly...@googlegroups.com

Very interesting Eric. It'd be neat to see you integrate that into
your patched tiddler macro.

rakugo

unread,
Nov 17, 2009, 8:34:24 AM11/17/09
to TiddlyWikiDev
I think something more powerful would be to add a data parameter to
the tiddler macro.
Have had a few discussions with Jeremy around this.

It would work like so:

<<tiddler MyTemplate data:foo>>

This would render the tiddler MyTemplate in the context of the tiddler
foo.
So for instance if the text of MyTemplate looks like this:

<<view title>> was last modified on <<view modified>>

You would get:
foo was last modified on {date}
where {date} is the value of foo's modified field.

I have some working code I am still finalising, but I wonder if this
would solve your problem with the benefit of clearer code.



On 15 Nov, 18:27, Michael Mahemoff <mich...@mahemoff.com> wrote:

Paul Downey

unread,
Nov 17, 2009, 8:55:22 AM11/17/09
to tiddly...@googlegroups.com
> <<tiddler MyTemplate data:foo>>
>
> This would render the tiddler MyTemplate in the context of the tiddler
> foo.

I like the idea, but dislike the formulation and the use of the name
"data". Suggest something more explicit, such as:

<<tiddler template:MyTemplate tiddler:foo>>

but that's without thinking of the implications or if this is a
generic parameter change, or only applies to the tiddler macro.

--
Paul (psd)
http://blog.whatfettle.com

rakugo

unread,
Nov 17, 2009, 9:07:02 AM11/17/09
to TiddlyWikiDev
I was thinking in terms of the existing syntax.
So at the moment <<tiddler MyTemplate>> would render the tiddler
MyTemplate.
The only different is that MyTemplate is currently rendered in the
context of the tiddler MyTemplate (itself).

So possibly context might be a better name then data?

My motivation here is I could imagine a macro (in fact I am working on
one)
which allows you to pass a filtered list of tiddlers through a
template
eg.<<tiddlers MyTemplate filter:[tag[systemConfig]]>>

I think this would be really useful for mimicking most types of loop
from a tiddlyweb templating perspective, but would also be a powerful
alternative to the forEachTiddler plugin...

Jon
Reply all
Reply to author
Forward
0 new messages