How do I pass a value returned by <$count> to a macro?

55 views
Skip to first unread message

c pa

unread,
Jun 30, 2015, 12:59:14 PM6/30/15
to tiddl...@googlegroups.com
I am unable to pass a value to a macro when that value has been generated by <$count>.

A demo of the problem: http://cpashow.tiddlyspot.com/#What_s_wrong_with_this

Here's the code:
\define getCountOfItemsInList(tiddlerName, fieldName)
<$count filter="[list[$tiddlerName$!!$fieldName$]]" />
\end
\define generateSelectWithNumberOptions(xnum)
    <br/>''executing generateSelectWithNumberOptions(xnum="$xnum$")''
    <$select>
        <$list filter="1 2 3 4 $xnum$">
            <option value=<<currentTiddler>> >
                <<currentTiddler>>
            </option>
        </$list>
    </$select>
\end
    Can I generate a number using a macro that calls &lt;$count&gt;?
        <<getCountOfItemsInList "What_s_wrong_with_this" "test">>
    (Yes)<br/>
    Can I generate a select containing a list of options by passing a number?
        <$macrocall $name="generateSelectWithNumberOptions"
                xnum=6
        />
    (Yes)<br/>
    Can I generate a select containing a list of options by passing a value from a macro that calls &lt;$count&gt;?
        <$macrocall $name="generateSelectWithNumberOptions"
                xnum=<<getCountOfItemsInList "What_s_wrong_with_this" "test">>
        />
    (No)<br/>

BJ

unread,
Jun 30, 2015, 2:55:39 PM6/30/15
to tiddl...@googlegroups.com
Hi c pa,
when you call a macro inside a widget (to return a parameter) it is not wikified, it only does string substitution of the parameter in to the content of the macro - this has led me to waste a lot of time as it is not what you would expect. I would write some javascript macro for this.

cheers

BJ

c pa

unread,
Jun 30, 2015, 5:09:08 PM6/30/15
to tiddl...@googlegroups.com
Excellent. Here's the code for that fix:

And here's a demo: http://cpashow.tiddlyspot.com/http://cpashow.tiddlyspot.com/#[[How to pass a filter count to a macro]] with a link to the code you can drag into your wiki

/*\
creator: _cpa
title: $:/_cpa/macros/filterCount.js
type: application/javascript
module-type: macro
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Information about this macro
Returns the count of rows returned by a filter.
*/
exports.name = "filterCount";
exports.params = [
{ name: "filter" }
];
/*
Run the macro
*/
exports.run = function(filter) {
	if(filter) {
	return $tw.wiki.filterTiddlers(filter).length;
	} else {
	return 0;
	}
}
})();

Reply all
Reply to author
Forward
0 new messages