Using procedure parameters in calls to my own javascript function

I have created a simple Javascript function “addDays” to play with dates which I am calling with an offset parameter from a procedure. “addDays” works just fine. <<addDays 1>> returns the string I want.

\procedure myProc(myOffset)
<$list filter="[prefix<addDays $myOffset$>]" />
\end

I want to use “addDays” in a myProc with myOffset as a parameters. I have tried <<>> <> $()$ and nothing around myOffset and I cannot get it to work.

Sorry, I am early on the TiddlyWiki coding learning curve and hope I have provided enough information to get a simple answer.

Thanks

\procedure definitions do not perform “lexical substitutions” (i.e., the $someparam$ and $(somevariable)$ syntax).

To use $myOffset$, try the older \define (aka “macro”) syntax, like this:

\define myProc(myOffset)
<$list filter="[prefix<addDays $myOffset$>]" />
\end

-e

Thanks Eric for the quick response. I had read that functions and procedures were preferred to define macros. Did I miss something?

You didn’t miss anything. Functions and procedures are generally preferred and typically result in cleaner/simpler code syntax that is easier to read. Nonetheless, there are still some use-cases where the $param$ and $(var)$ macro substitution syntax comes in handy.

-e

Hi Angus,

on a side note, I have recently implemented my chores in Tiddlywiki, which requires me to work with dates (due-/done-date) a lot.

I ended up writing my own filters to work with dates in YYYY-MM-DD format (which is the format used by <input type="date">-tags), which take a date, and calculate a new date from it.

As a simple example, with my filters this became possible (here: from today, find the next Thursday and set the due date accordingly; there’s a lot more filters, like delta_days[N] for what you’ve described above):

<$button>
  <$action-setfield done_date={{{ [today[]] }}} />
  <$action-setfield due_date={{{ [<today>next_weekday[4]] }}} />
  Task done!
</$button>

Not sure if that would fit what you’re looking for, but maybe it’s close enough to serve as an example or basis for your own work.
It required some JavaScript, though, and the plugin I’ve written is still quite rough around the edges (it works fine, but I feel it may need some optimization and finetuning). You could find my plugin on Github, if you want to have a look.

s.