On Nov 17, 8:19 pm, Trey <[email protected]> wrote:
> I am trying to write a forEachTiddler script to display any tiddlers
> that are tagged with today's date.  In all my work I use a custom date
> format Year, Month, Day, with leading zeros (as in 20101117, the date
> of this post).
>
> I've almost got it working!  Here is my script.
>
> <<forEachTiddler
>     sortBy
>         'tiddler.created'
>         descending
>
>     script
>         '
>         function lastDays(tiddler) {
>                 var currentTime = new Date()
>                 var month = currentTime.getMonth() + 1
>                 var day = currentTime.getDate()
>                         if (day<10)
>                                 {
>                                 day = "0" + day;
>                                 }
>                 var year = currentTime.getFullYear()
>                 year = year.toString();
>                 day = day.toString();
>                 month = month.toString();
>                 var today = (year + day + month)
>
>     if (tiddler.tags.contains(today))
>                 return "* [[" + tiddler.title + "]]\n";
>             else
>                 return "";}
>
>         '
>     write 'lastDays(tiddler)'
>
>
>
> The issue is that the line
>    if (tiddler.tags.contains(today))
> doesn't reference the variable "today".
> It works if I hardcode a date in there.  And I know that the "today"
> variable is outputting in the correct format.  I just don't know how
> to get the variable "today" into tiddler.tags.contains().
>
> any help is very much appreciated!  I did my homework on this but I'm
> definitely a beginner at javascript.  If there is an obvious shortcut
> to this function I've overlooked, please do enlighten me.
>
> Thanks TW dev group!

You don't need to do all that work (though it is a good learning
exercise)...

Instead, you can use the TW core's <<list>> macro to render a bullet
list of selected tiddler titles, based on a matching tag value:
   <<list filter [tag[tagvalue]]>>

For your purposes, you need to *generate* the desired tag value from
the current date.  Using the TW core's .formatString method for
javascript date objects, you can write:
   new Date().formatString('YYYY0MM0DD')
to get the current date as a text string in the indicated format

Lastly, you can use an "evaluated parameter" in the <<list>> macro to
construct the tag filter as a text string:
   {{'[tag['+new Date().formatString('YYYY0MM0DD')+']]'}}

Thus, putting it all together:

<<list filter {{'[tag['+new Date().formatString('YYYY0MM0DD')+']]'}}>>

That should do it...

Note: to find tiddlers based on combinations of tag values using
Boolean logic (and/or/not), e.g.,
   "Tag1 and (Tag2 or not (Tag3 or Tag4))"
please see:
   http://www.TiddlyTools.com?#MatchTagsPlugin
   http://www.TiddlyTools.com?#MatchTagsPluginInfo

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