Trying to access tiddler.title in foreachtiddler in a template

14 views
Skip to first unread message

shavinder

unread,
Apr 3, 2009, 7:13:33 AM4/3/09
to TiddlyWiki
I have a tiddler containing student record, it is connected with its
own StudentFormViewTemplate and StudentFormEditTemplate. In the view
template i have a newTiddler macro which is supposed to create a
Qualifications tiddler. This new qualification tiddler should be
tagged with the title of the Student tiddler when it is created. But
since multiple qualification tiddlers can be created from one parent
student tiddler i need to count any alreadt existing qualifications
tiddlers and attach a suffix to the title of the new qualifications
tiddler. so for example lets say we have a student tiddler with title
as 'rollno10', when i create the first qualification it should be
titled as 'rollno10-qualification1' and tagged as rollno10. in order
to do this i am doing this in StudentFormViewTemplate:

<span macro='newTiddler title: "<<forEachTiddler where
'tiddler.tags.contains(tiddler.title)' write '""' end
'{{tiddler.title}}+"-Qualification" + count' none '""' >>" label:"Add
Qualification" tag:{{tiddler.title}} tag:"QualificationForm"
template:"QualificationFormEditTemplate" '></span>

But cannot make it work.
Thanks in advance.
please try the AddNewStudent link in main menu here
http://shavinz-trial-tw.tiddlyspot.com/

Eric Shulman

unread,
Apr 3, 2009, 7:25:06 AM4/3/09
to TiddlyWiki
> <span macro='newTiddler title: "<<forEachTiddler where
> 'tiddler.tags.contains(tiddler.title)' write '""' end
> '{{tiddler.title}}+"-Qualification" + count' none '""' >>"  label:"Add
> Qualification" tag:{{tiddler.title}} tag:"QualificationForm"
> template:"QualificationFormEditTemplate" '></span>

Macros don't generate text output... they create DOM elements in the
browser. Thus, you can't put a macro inside another macro and have
the output of one inserted as text into the parameter list of the
other.

instead of attempting
title:"<<forEachTiddler ...>>"

you should use a "computed parameter" (a bit of javascript, enclosed
in doubled curly-braces), like this:

title:{{ ... calculate title here ... }}

You can get the array of tiddlers with a given tag, use this function:
store.getTaggedTiddlers('tagValue')

Thus, for your purposes:

title:{{ tiddler.title+'-Qualification'+store.getTaggedTiddlers
(tiddler.title).length+1 }}

enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios

shavinder

unread,
Apr 3, 2009, 12:49:33 PM4/3/09
to TiddlyWiki
Thank you. It worked.
Reply all
Reply to author
Forward
0 new messages