Using transclusion in regular expressions

69 views
Skip to first unread message

Pin Tail

unread,
Aug 18, 2018, 9:40:12 AM8/18/18
to TiddlyWiki
I'm trying to transclude the title of a tiddler into a regular expression and can't figure out why it's not working.

I've created a year summary template tiddler, and in a given year, I want to show for each month how many tiddlers have a date (in their startdate date field) in that month. The idea is that the yeartemplate tiddler would be transcluded into a tiddler whose title is simply the year. I want to use a regular expression which combines the title of the transcluding tiddler (i.e. the year) with each month, in order to show a month-by-month breakdown.

So my 2014 tiddler just looks like this:
{{||yeartemplate}}

And the yeartemplate tiddler, looks like this (focusing just on the month of October here, for brevity). 

<$set name="filt" value="^{{!!title}}10">
Number of entries: <$count filter="[regexp:startdate<filt>]"/>
</$set>

However, this doesn't work. I get a count of zero even though I know there are many matching tiddlers. To try and work out what the problem is, I've extended my yeartemplate tiddler to compare the transclusion method with writing out the regexp directly:

<$set name="filt" value="^201410">
<<filt>>

Number of entries: <$count filter="[regexp:startdate<filt>]"/>
</$set>

<$set name="filt" value="^{{!!title}}10">
<<filt>>

Number of entries: <$count filter="[regexp:startdate
<filt>]"/>
</$set>

The results of the above template, when transcluded into a tiddler with the title "2014" are given below:

^201410 Number of entries: 23

^201410 Number of entries: 0


Even though the "filt" variable which contains the regular expression is identical after transclusion, it doesn't find the matching tiddlers which are found when an identical regexp is hard coded. What's going on?

Mark S.

unread,
Aug 18, 2018, 9:51:13 AM8/18/18
to TiddlyWiki
You're trying to "glue" the result of a transclusion into a string. Whenever you need to do that, you almost always need a macro. This worked in my quick test:

\define filt() ^$(dt)$10
<$set name="dt" value={{!!title}}>

Number of entries: <$count filter="[regexp:startdate<filt>]"/>
</$set>

HTH
-- Mark

Pin Tail

unread,
Aug 18, 2018, 9:57:34 AM8/18/18
to TiddlyWiki
Amazing. Thanks very much, works fine.

@TiddlyTweeter

unread,
Aug 18, 2018, 10:16:25 AM8/18/18
to TiddlyWiki
Mark S., you and Eric got together you likely whip up a decent practical TW manual in a couple of months. Just saying. Both of you know how to write. Both of you know a lot.

Frankly I get fed up with seeing excellence thrown to the wind of Google Groups. Far better that the lessons persisted.

I feel we piss away skill here everyday--to me it makes no sense to learn something in a great post then lose it to the Google Swamp.

Josiah

Eric Shulman

unread,
Aug 18, 2018, 10:16:39 AM8/18/18
to TiddlyWiki
On Saturday, August 18, 2018 at 6:51:13 AM UTC-7, Mark S. wrote:
You're trying to "glue" the result of a transclusion into a string. Whenever you need to do that, you almost always need a macro. This worked in my quick test: 
\define filt() ^$(dt)$10
<$set name="dt" value={{!!title}}>
Number of entries: <$count filter="[regexp:startdate<filt>]"/>
</$set>


In this use-case, you don't actually need a macro... you can use the <<wikify>> widget to "glue" the parts together, like this:

<$wikify name="filt" text="^{{!!title}}10">

Number of entries: <$count filter="[regexp:startdate
<filt>]"/>
</$wikify>

* use $wikify instead of $set (2 places)
* use text= instead of value=

enjoy,
-e
Reply all
Reply to author
Forward
0 new messages