<style>.message-of-the-day { color: red;}</style>
<$wikify mode="inline" name="dayofmonth_val" text=<<now DD>> ><$set name="messages" filter="
[[Message 1]]
[[Message 2]]
[[Message 3]]
[[Message 4]]
"><$set name="list_length" filter="[enlist<messages>count[]]"><$set name="list_index" filter="[<dayofmonth_val>remainder<list_length>]"><$list variable="result" filter="[enlist<messages>nth<list_index>]"><h1><span class="message-of-the-day">Message of the day: <<result>></span></h1></$list></$set></$set></$set></$wikify>
var messages = ["Message 1", "Message 2", "Message 3", "Message 4"]
var result = messages[new Date().getDate() % messages.length]
//and then display the result var in anyway you see fit
\define list-of-messages() [[Message 1]] [[Message 2]] [[Message 3]] [[Message 4]]
\define list-of-messages()
[[Message 1]]
[[Message 2]]
[[Message 3]]
[[Message 4]]
\end
<<messageoftheday "[[somefilter expression]]">>
<h1><span class="message-of-the-day">Message of the day:
<<messageoftheday "
[[Message 1]]
[[Message 2]]
[[Message 3]]
[[Message 4]]
"
>>
</span></h1>
/*\
title: $:/melvin/macros/messageoftheday.js
type: application/javascript
module-type: macro
Macro to output a message of the day from a filter
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Information about this macro
*/
exports.name = "messageoftheday";
exports.params = [
{name: "filter"},
];
/*
Run the macro
*/
exports.run = function(filter) {
var defaultFilter = "[[the default message has arrived]]";
filter = filter || defaultFilter;
var messages = this.wiki.filterTiddlers(filter);
var adjustedDate = new Date().getDate() - 1;
var messagesIndex = adjustedDate % messages.length;
var result = messages[messagesIndex];
var debug = [" ", result, messagesIndex, adjustedDate].join(" "); // concatenate the debug variable to result if you want to see any variables of interest
return result;
};
})();
<$setname="messages" select=<<now DD>>
filter="[[Message 1]] [[Message 2]][[Message 3]][[Message 4]]
..."><<messages>></$set>
I love it when one persons idea is made even more elegant by another.
It is also a great source of code methods and patterns which are easier to learn than reverse engineering.
Thanks
Tony
Mat you method looks close to a "case" structure.
Love it
Tony
--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/66Qpgtbv_-w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/b3ad9b79-e8eb-4478-bdec-291d9afc8d7d%40googlegroups.com.
Hood on you for taking the JavaScript challenge. I am sure it will help you and our community.
Of course you can see I mat and others always like a coding challenge and we can't help ourselves.
Tony
\define tid() x$(item)$
<$set name="dd" value=<<now DD>> >
<$list filter="[tag[message]removeprefix[message ]match<dd>]" variable=item>
<$transclude tiddler=<<tid>> mode=block/>
</$list>
</$set>
Yet another approach.
Love it
Tony
\define msg-field() msg-<<now "DD">
\define msg-tiddler() tiddlername
then in any location
<$transclued tiddler=<<msg-tiddler>> field=<<msg-field>> />
store the messages in fields msg-1 msg-2 .... In tiddler name.
In this way you could even have alternative tiddlers with another set of messages for the day. Even 12 for different for every day of the year.
Regards
Tony