I believe this is possible with pure wikitext!

One solution:
I have 32 tiddlers each contains a message
Each tiddler have a field called day and message of day one has 1 as the 
day value
Write a list widget with a filter to extract the day number of current data
Match against field value of tiddlers has such field
Show the one match


*Side note*
*I believe pure wikitext is a better way to write JS*
*Many of us understand wikitext while few understand JS*

--Mohammad
On Wednesday, September 18, 2019 at 4:50:58 AM UTC+4:30, Melvin wrote:
>
> This took me a while, but I found a way to create a message of the day 
> generator which changes the message given on how many messages you have and 
> what day of the month it is. 
>
> You add the messages in [[]] and the code will do the rest :D
>
> The current 'bug' is that it will only allow you to have about 30 
> messages, as it cannot display more messages of the day than there are days 
> in the month.
>
> Copy/paste this Tiddler and see what message of the day you get!
>
> <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>
>
>
> My question here is: is there any way to do this more efficient?
> In JavaScript this is the equivalent of: 
>
> 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
>
> Which would be so much easier to write.
>
> I guess I need to learn how to create JS macro's or something similar.
>
> What do you think?
>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/d585107c-67f6-4326-82d4-9c216f3bbdb5%40googlegroups.com.

Reply via email to