> I'm trying to create a write clause using forEachTiddler that will
> write the tags of the resulting tiddlers, but only those tags that
> begin with upper case letters, for example:
> I have tiddler named "War and Peace" tagged as "book", "toRead" & "Leo
> Tolstoy".  I want the results to show:
> "War and Peace by Leo Tolstoy" using something like this:
> <<forEachTiddler where 'tiddler.tags.contains("book")' write
> '"[["+tiddler.title+"]] by "+tiddler.tags'>>

in the write clause, instead of using just using
   tiddler.tags
you can use this complicated expression:
   ("[["+tiddler.tags.map(function(e){if(e.substr(0,1).match(/[A-
Z]/))return e;}).join("]] [[")+"]]").readBracketedList().join(" and ")

here's how it works:

Using the .map(...) method on the tags array, it applies a function
that looks for tag values whose first letter is a capital letter.  Any
non-capitalized tags in the array are returned as null values.

Then, the mapped array is joined together using doubled-square
brackets around each tag and then broken apart again using
readBracketedList().  This is removes any null values from the array,
resulting in an array containing only the capitalized tag values.

To format these tag(s) as text output, the array elements are then
joined with " and ", so that, for example, if [[Elements of Style]] is
tagged with both "Strunk" and "White", then the resulting output would
display:
   Elements of Style by Strunk and White
instead of
   Elements of Style by Strunk,White

enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/tiddlywiki?hl=en.

Reply via email to