How to fetch tiddlers tagged with THIS tiddlers title - in a template...

14 views
Skip to first unread message

Måns

unread,
Feb 25, 2009, 4:52:43 AM2/25/09
to TiddlyWiki
I've searched the group and tw.org - trying to solve this on my own
for a long time - and I know that the solution MUST be trivial - .
Please tell me what to write to fetch tiddlers tagged with this
tiddlers title.
I'm using it in this context - wanting to make a template that changes
results depending on the tiddlers title:

Template:
<<forEachTiddler
where
'tiddler.tags.contains("
this tiddlers title <- This is what I need - What is the correct
syntax/word for fetching it??
") && tiddler.data("Navn")'
sortBy 'tiddler.data("Navn")'
write
'(index < 200) ? "|"+(index+1)+"|[["+tiddler.title+"]]|
[["+tiddler.data("Gang")+"]]|[["+tiddler.data("Værelse")
+"]]|"+tiddler.data("Dato")+"|\n" : ""'
begin '"|sortable|k\n|!#|Navn|Gang|Værelse|SDD|h\n"'
end 'count+" elever i kontaktgruppen\n"'
none '"Ingen elever i kontaktgruppen\n"'
>>
<<snapshot print label:Udskrift prompt:Udskriv id:viewer>><<fontSize>>

YS Måns Mårtensson



Måns

unread,
Feb 25, 2009, 5:35:22 AM2/25/09
to TiddlyWiki
Hi again - I post this bonus-question here, because it's another
syntaxproblem in the same context...

I would like to have 2 extra columns in the resulting table that
toggles tags on the tiddler in the corresponding row.

Like this: <<toggleTag SomeTag [[Tiddler title from corresponding
row]] nolabel>>

In full context:

<<forEachTiddler
where
'tiddler.tags.contains("
this tiddlers title <- This is what I need - What is the correct
syntax/word for fetching it??
") && tiddler.data("Name")'
sortBy 'tiddler.data("Name")'
write
'(index < 200) ? "|"+(index+1)+"|[["+tiddler.title+"]]|
[["+tiddler.data("A")+"]]|[["+tiddler.data("B")
+"]]|"+<<toggleTag A [[Tiddler title from corresponding row]]
nolabel>>|"+<<toggleTag B [[Tiddler title from corresponding row]]
nolabel>>"|\n" : ""'
begin '"|sortable|k\n|!#|Name|A|B|ToggleTagA|ToggleTagBh\n"'
end 'count+" Tiddlers tagged with this tiddlers title\n"'
none '"No tiddlers tagged with this tiddlers title\n"'

Is this possible??

Right now I'm doing it "by hand" and it's very tedious.
The problem is to integrate the toggleTagmacro into the
'forEachTiddler where ... macro'.
I've tried - but putting toggleTagmacro into forEachTiddler macro
breaks the forEachTiddler macro - when I try....
If You know how to do this - I would be very happy to know!!

Here's my actual code for one of my 30 tiddlers - It would be very
nice to be able to make a template instead - then I would be able to
use my tw as a template for a new set of data:


|sortable|k
|[img(25%,auto)[Name|http://xxxxxx.jpg]]|[[A]]|[[B]]|[[C]]|[[D]]|h
| @@Remember to update!@@ |!<<tiddler AUpdate>>|!<<tiddler BUpdate>>|!
<<tiddler CUpdate>>|!<<tiddler DUpdate>>|
|[[1]]|<<toggleTag A [[1]] nolabel>>|<<toggleTag B [[1]] nolabel>>|
<<toggleTag C [[1]] nolabel>>|<<toggleTag D [[1]] nolabel>>|
|[[2]]|<<toggleTag A [[1]] nolabel>>|<<toggleTag B [[2]] nolabel>>|
<<toggleTag C [[2]] nolabel>>|<<toggleTag D [[2]] nolabel>>|
|[[3]]|<<toggleTag A [[3]] nolabel>>|<<toggleTag B [[3]] nolabel>>|
<<toggleTag C [[3]] nolabel>>|<<toggleTag D [[3]] nolabel>>|
|[[4]]|<<toggleTag A [[4]] nolabel>>|<<toggleTag B [[4]] nolabel>>|
<<toggleTag C [[4]] nolabel>>|<<toggleTag D [[4]] nolabel>>|
etc|etc ....

YS Måns Mårtensson

Ken Girard

unread,
Feb 25, 2009, 9:02:00 AM2/25/09
to TiddlyWiki

For your first question:
<<forEachTiddler
where
' tiddler.tags == context.inTiddler.title '

For the second:

'(index < 200) ? "|"+(index+1)+"|[["+tiddler.title+"]]|
[["+tiddler.data("A")+"]] | [["+tiddler.data("B")
+"]] | <<toggleTag A [["+tiddler.title+"]] nolabel \>\> | <<toggleTag
B [["+tiddler.title+"]]
nolabel \>\> |\n" : ""'

But I couldn't get it to have no label.

Ken Girard

Måns

unread,
Feb 25, 2009, 2:36:11 PM2/25/09
to TiddlyWiki
Hi Ken

Thankyou for taking your time to answer my question.
I'm sorry to say that I cannot make it work in my context.
Here's what I done:

When I put ' tiddler.tags == context.inTiddler.title ' in place of
'tiddler.tags.contains(" This tiddlers name") - then it gives me an
error = <<forEachTiddler ...>>:Unknown action '&&'.

I need the forEachTiddler macro to sort data from the tiddlers which
are tagged with THIS tiddlers name (as i did before) - so how do I get
it to accept && ??

For the second:


On 25 Feb., 15:02, Ken Girard <ken.gir...@gmail.com> wrote:
> For your first question:
> <<forEachTiddler
>     where
>         ' tiddler.tags == context.inTiddler.title '
>
> For the second:
> If I write this:
<<forEachTiddler
where
' tiddler.tags == context.inTiddler.title '
write
'(index < 200) ? "|"+(index+1)+"|[["+tiddler.title+"]]|
[["+tiddler.data("Gang")+"]] | [["+tiddler.data("Værelse")
+"]] | <<toggleTag HU [["+tiddler.title+"]] nolabel \>\> | <<toggleTag
Hjem [["+tiddler.title+"]]
nolabel \>\> |\n" : ""'
begin '"|sortable|k\n|!#|Navn|Gang|Værelse|HU|Hjem|h\n"'
end 'count+" elever i kontaktgruppen\n"'
none '"Ingen elever i kontaktgruppen\n"'
>>

I get: <<forEachTiddler ...>>: SyntaxError: unterminated string
literal

Sorry If I'm doing something basically wrong - it appears to me though
that the faults I get are because of syntax - and not because I´m
using wrong parameters...

YS Måns Mårtensson

Måns

unread,
Feb 25, 2009, 3:53:49 PM2/25/09
to TiddlyWiki
I will try to show you the two different tables that I would like to
mix into 1 - and make into a table.
The idea is that I make a TeacherTemplate - and a Button which a call
NewTeacher.
The button makes a new tiddler with the template and I name the
tiddler with a teachers initials.

I have another template for the students working in a similar way -
except I spell their names fulltext.

I tag the students with the initials of their teacher - and the result
is that the teachers tiddler gets a sortable table with students names
and data + up to 5 toggletags - for markings like: sick leave and
going home/staying at school for the weekend a.s.o - I'm working at a
Danish boarding school.

Here's my first tiddler fetching information from the students
tiddlers (This is the one that I would like to be able to "fetch" the
title of the tiddler that it is contained in "Teachers initials"):

<<forEachTiddler
where
'tiddler.tags.contains("TeachersInitials") && tiddler.data("Name")'
sortBy 'tiddler.data("Name")'
write
'(index < 200) ? "|"+(index+1)+"|[["+tiddler.title+"]]|
[["+tiddler.data("House")+"]]|[["+tiddler.data("Room")
+"]]|"+tiddler.data("Date")+"|\n" : ""'
begin '"|sortable|k\n|!#|Name|House|Room|Date|h\n"'
end 'count+" this teachers students\n"'
none '"No students for this teacher\n"'
>>

The second tiddler that I have had so much trouble in "handcrafting"
is this one(I would like it to be integrated in the first one - plus
the toggletags and fetching the students names from tiddlers tagged
with the title of the teachers tiddler (initials)):

|sortable|k
|NamesofStudents|toggles[[A]]|[[B]]|[[C]]|[[D]]|h
| @@Remember to update!@@ |!<<tiddler AUpdate>>|!<<tiddler BUpdate>>|!
<<tiddler CUpdate>>|!<<tiddler DUpdate>>|
|[[Student1]]|<<toggleTag A [[Student1]] nolabel>>|<<toggleTag B
[[Student1]] nolabel>>|
<<toggleTag C [[Student1]] nolabel>>|<<toggleTag D [[Student1]]
nolabel>>|
|[[Student2]]|<<toggleTag A [[Student2]] nolabel>>|<<toggleTag B
[[Student2]] nolabel>>|
<<toggleTag C [[Student2]] nolabel>>|<<toggleTag D [[Student2]]
nolabel>>|
|[[Student3]]| etc|etc ....

I'm sure that Ken answered my question - but I'm so unfamiliar with
programming/writing code - that I cannot figure out where I am doing
sth wrong.... sorry.

If somebody would try to connect these ideas into one table - and
(maybe) give me the full code and context - then I just might make it
work - and it could spare me hours of typing (Next time I'll set it
up.... )

A danish novice trying to keep up the good spirit :-)

Måns Mårtensson

Ken Girard

unread,
Feb 25, 2009, 4:03:32 PM2/25/09
to TiddlyWiki
Make all of the section between 'write' & 'begin' into one line.
Google Groups is adding in extra line breaks in that confuse it.

Ken Girard
> > > > YS Måns Mårtensson- Hide quoted text -
>
> - Show quoted text -

Måns

unread,
Feb 25, 2009, 4:26:06 PM2/25/09
to TiddlyWiki
I still get errormessage: <<forEachTiddler ...>>: Unknown action '&&'.
for this code:
<<forEachTiddler
where
' tiddler.tags == context.inTiddler.title '&& tiddler.data
("Navn")'
sortBy 'tiddler.data("Navn")'
write '(index < 200) ? "|"+(index+1)+"|[["+tiddler.title+"]]|
[["+tiddler.data("Gang")+"]]|[["+tiddler.data("Værelse")
+"]]|"+tiddler.data("Dato")+"|\n" : ""' begin '"|sortable|k\n|!#|Navn|
Gang|Værelse|Dato|h\n"'
end 'count+" this teachers students\n"'
none '"No students for this teacher\n"' >>


Måns

unread,
Feb 25, 2009, 4:40:14 PM2/25/09
to TiddlyWiki
When I write this:
<<forEachTiddler
where
' tiddler.tags == context.inTiddler.title '
'(index < 200) ? "|"+(index+1)+"|[["+tiddler.title+"]]|[["+tiddler.data
("A")+"]] | [["+tiddler.data("B") +"]] | <<toggleTag A
[["+tiddler.title+"]] nolabel \>\> | <<toggleTag B [["+tiddler.title
+"]] nolabel \>\> |\n" : ""' >>

I get this: <<forEachTiddler ...>>: Unknown action '(index < 200) ?
"|"+(index+1)+"|[["+tiddler.title+"]]|[["+tiddler.data("A")+"]] |
[["+tiddler.data("B") +"]] | <<toggleTag A [["+tiddler.title+"]]
nolabel \>\> | <<toggleTag B [["+tiddler.title+"]] nolabel \>\> |\n" :
""'.

cmari

unread,
Feb 25, 2009, 5:59:23 PM2/25/09
to TiddlyWiki
Hi Måns,
I started with the most recent of your messages so I don't know
whether this will get you any further toward your ultimate goal, but
you can make the last version you posted work by adding back in the
word "write" .

When I tested that, I noticed that of course using a checkbox to add a
tag to a tiddler listed on your table will have the result that the
tiddler will have two tags - which means it won't meet the search
criteria of 'tiddler.tags == context.inTiddler.title' anymore. If you
want a more inclusive approach, you could use "contains" instead of
"==". So if you were going to do that, the new version restoring the
somehow lost "write" would start like this:

<<forEachTiddler where ' tiddler.tags.contains
(context.inTiddler.title)' write '(index < 200) ? "|"+.....
cmari

Måns

unread,
Feb 25, 2009, 7:03:30 PM2/25/09
to TiddlyWiki
Hi cmari and Ken

NOW IT WORKS - (almost) ALL OF IT!! (The rest is just refinements)
I'm very sorry for my outbursts and long sentences in this post - but
this is very great news for me - and i think you should know - Read it
or leave it ... It's just me getting excited beeing a novice and
all...

What you've just written makes everything fall into place. What Ken
wrote was essential for getting toggletags into my forEachTiddler
macro - and You made me understand why I couldn't make it work untill
I changed == into: contains ...

When I asked the question, I thought that I needed the complete code
from someone who knows how to write code - because it's way too
complicated for me to figure out myself - but You just explained it in
a way that makes me understand what is going on.

Now after 3 weeks of fiddling around in the dark - it suddenly
works :-)

Thank You very very much - Both of you
Now I'm able to populate tiddlers with "interactive" content (toggles
tags remotely) and I don't have to write all students names manually
- .... as I've done up till now - You've really saved my day - and
next semester too!!!!

Now I'm curious if I can make a template where the toggletagging works
as it should - I've tried to include toggletags in templates before -
and they didn't work (maybe because the toggletagmacro worked inside
the templatetiddler instead of the actual tiddler it was copied to??).

I will give it a try - even so - if I don't succeed I won't give up -
I will also try to compose a newtiddler button with prefilled text to
see if it does the trick - and again if that doesn't work - I just
copy my code into each teachers tiddler by hand..

Here's the actual code combining everything I wanted to list in the
tables and IT WORKS LIKE A CHARM!!
I really hope that you understand that this has made my day - and days
to come!! - Thank you again - VERY much!!
:

<<forEachTiddler where ' tiddler.tags.contains
(context.inTiddler.title)' write '(index < 200)? "|"+(index+1)+"|
[["+tiddler.title+"]]|[["+tiddler.data("House")+"]] | [["+tiddler.data
("Room") +"]] | <<toggleTag HereForTheWeekend [["+tiddler.title+"]]
nolabel \>\> | <<toggleTag SickLeave [["+tiddler.title+"]] nolabel \>
\> |\n" : ""'begin '"|sortable|k\n|!#|Name|House|Room|
HereForTheWeekend|SickLeave|h\n"'
end 'count+" students\n"' none '"No students for this teacher\n"'
>>

YS Måns Mårtensson

Måns

unread,
Feb 25, 2009, 9:42:43 PM2/25/09
to TiddlyWiki
Alert - Alert!!!

I don't know what makes it happen - but when I've saved the code - and
reload - it looses all the backslashes (\) - and the code doesn't
work anymore!!!

This:
<<forEachTiddler where ' tiddler.tags.contains
(context.inTiddler.title)' write '(index < 200)?

"|"+(index+1)+"|[["+tiddler.title+"]]|[["+tiddler.data("Gang")+"]] |
[["+tiddler.data("Værelse") +"]] | <<toggleTag HU

[["+tiddler.title+"]] nolabel \>\> | <<toggleTag Syg [["+tiddler.title
+"]] nolabel \>\> |\n" : ""'begin

'"|sortable|k\n|!#|Navn|Gang|Værelse|HU|Syg|h\n"'
end 'count+" K-elever\n"' none '"Ingen K-elever i denne gruppe\n"'
>>

Becomes:

<<forEachTiddler where ' tiddler.tags.contains
(context.inTiddler.title)' write '(index < 200)? "|"+(index+1)+"|
[["+tiddler.title+"]]|[["+tiddler.data("Gang")+"]] | [["+tiddler.data
("Værelse") +"]] | <<toggleTag HU [["+tiddler.title+"]] nolabel >> |
<<toggleTag Syg [["+tiddler.title+"]] nolabel >> |n" : ""'begin '"|
sortable|kn|!#|NavnGang|Værelse|[[HU]]|[[Syg]]|hn"'
end 'count+" K-elevern"' none '"Ingen K-elever i denne gruppen"'>>

As You can see ALL backslashed vanish in thin air!! When I put them in
again everything works again.....

I am using BidiX's ITw ... and I've never experienced anything like
this before... very very weird...

Please help me...

YS Måns Mårtensson

Ken Girard

unread,
Feb 27, 2009, 7:00:03 AM2/27/09
to TiddlyWiki
Dissapering backslashes problem solved in a different posting list.
http://groups.google.com/group/TiddlyWiki/browse_thread/thread/e750e67cd4a0f7f9?hl=en

Ken Girard
Reply all
Reply to author
Forward
0 new messages