forEachTiddler - dyamic search conditions

24 views
Skip to first unread message

c.skye

unread,
Oct 20, 2007, 9:49:12 AM10/20/07
to TiddlyWiki
rather than sing forEachTiddler plugin to search for static conditions
such as
where
'tiddler.tags.contains("project")'

I want the replace "project" with a dynamicly generated cndition, a
simple java script for example that returns the tag name of the
current tiddler and then forEachTiddlewr searches for other tiddlers
with that same tag. How do I insert a java script in the place of
"project".

I have InLineJavaScript installed

Eric Shulman

unread,
Oct 20, 2007, 10:16:08 AM10/20/07
to TiddlyWiki
> 'tiddler.tags.contains("project")'
> I want the replace "project" with a dynamicly generated condition,

> simple java script for example that returns the tag name of the
> current tiddler and then forEachTiddlewr searches for other tiddlers
> with that same tag. How do I insert a java script in the place of
> "project".

Using
http://www.TiddlyTools.com/#InlineJavascriptPlugin
you can embed the following script in your tiddler, just before the
<<forEachTiddler>> macro invocation to set a global variable based on
the current tiddlers tag...

<script>
var here=story.findContainingTiddler(place); // rendered DOM
element
if (!here) return; // not in a tiddler... do nothing.
var tid=here.getAttribute("tiddler"); // tiddler ID (title)
var t=store.getTiddler(tid); // stored tiddler data object
config.currentProject=t.tags[0]; // assume *first* (or only) tag
</script>

Then, in your <<forEachTiddler>> call, you can reference that global
variable like this:
'tiddler.tags.contains(config.currentProject)'

Note: "config" is a global object, created by the TW core, and
contains many critical internal TW values (such as config.options.*,
config.macros.* and config.messages.*, among others). Be sure you use
a property name that doesn't step on any of the existing TW core
properties. The best way to ensure this is to give the property name
a distinct prefix such as your initials (e.g.
"config.ELS_currentProject").

enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios

c.skye

unread,
Oct 20, 2007, 10:21:07 AM10/20/07
to TiddlyWiki
Thanks for the quick response - I think that explains it well!!!!

Skye

Uwe

unread,
Oct 20, 2007, 1:14:34 PM10/20/07
to TiddlyWiki
Assuming that the tiddler with the <<forEachTiddler>> call is named
ShowMe and has the tags ene, mene, mane, moo.

How can the forEachTiddlerPlugin find the tiddlers with *all* these
tags of ShowMe, but *not* the tiddler ShowMe?

-Uwe

Udo Borkowski

unread,
Oct 21, 2007, 5:47:28 AM10/21/07
to Tiddl...@googlegroups.com

Assuming that the tiddler with the <<forEachTiddler>> call is named
ShowMe and has the tags ene, mene, mane, moo.

How can the forEachTiddlerPlugin find the tiddlers with *all* these
tags of ShowMe, but *not* the tiddler ShowMe?


<<forEachTiddler
where 'tiddler != context.inTiddler &&
tiddler.tags.sort().join("]]") == context.inTiddler.tags.sort().join("]]")'
>>
  • The tiddler != context.inTiddler ensure the tiddler containing the macro call is not listed.
  • tiddler.tags.sort().join("]]") creates a string with all tags of the tiddler, with the tags sorted alphabetically and separated by "]]". The "]]" string is used because it cannot be part of any tag name so it is fine to use it as a separator between tags.
  • A "sorted tags string" is created both for the current tiddler and the tiddler containing the macro. If both strings are equal both tiddlers have the same tags.
  • Instead of context.inTiddler you may also use context.viewTiddler, especially when you are working with the <<tiddler...>> macro.

(see http://tiddlywiki.abego-software.de/#%5B%5BList%20all%20Tiddlers%20that%20have%20the%20exact%20same%20tags%20as%20the%20tiddler%20containing%20the%20ForEachTiddler%20macro%20call%5D%5D)


Udo

----------
Udo Borkowski
http://www.abego-software.de


Uwe

unread,
Oct 21, 2007, 7:05:52 AM10/21/07
to TiddlyWiki
Thanks for the solution, Udo,

it works fine!

Do you also have a solution for the following problem?

Assuming that the tiddler with the <<forEachTiddler>> call is named

ShowMe and has the tags ene and mene.

How can the ForEachTiddlerPlugin find all tiddlers with the tag ene
*or* with the tag mene (or both), when there are perhaps many other
tags in the tiddlers?

(The ForEachTiddlerPlugin must use the tags from the ShowMe tiddler.)

-Uwe


Udo Borkowski

unread,
Oct 21, 2007, 7:34:48 AM10/21/07
to Tiddl...@googlegroups.com
Assuming that the tiddler with the <<forEachTiddler>> call is named
ShowMe and has the tags ene and mene.

How can the ForEachTiddlerPlugin find all tiddlers with the tag ene
*or* with the tag mene (or both), when there are perhaps many other
tags in the tiddlers?


I guess this should do it:

    <<forEachTiddler where 'tiddler.tags.containsAny(context.inTiddler.tags)' ... >>

(Not tested)


Udo

----------
Udo Borkowski
http://www.abego-software.de



Uwe

unread,
Oct 21, 2007, 12:22:46 PM10/21/07
to TiddlyWiki
Udo, your tip solves the problem, thank you very much for your help.

<<forEachTiddler where
'tiddler.tags.containsAny(context.inTiddler.tags)'
... >>

-Uwe

Reply all
Reply to author
Forward
0 new messages