<$list filter="[!has[draft.of]tag[Stocks]]">
* <$link to={{!!title}}><$view field="title"/> </$link>@@color:red;( to be discarded : <$macrocall $name="day-left" bestbefore={{!!bestbefore}} />)@@
</$list>
* <$link to={{!!title}}><$view field="title"/> </$link> <$reveal type="match" state="<$macrocall $name="day-left" bestbefore={{!!bestbefore}} />" text="YES">@@color:red;( to be discarded )@@ </$reveal>
but the result of that is not working. Instead it displays:
<$reveal type="match" state="YES" text="YES">( to be discarded ) </$reveal>
<$reveal type="match" state="NO" text="YES">( to be discarded ) </$reveal>
this.setVariable("outval",whatever_the_return_variable_is) ;What I would ideally like to do is that the text in red (to be discarded) only appears if the return of the macro is YES.
I would like to use the RevealWidget but can't make it works. Here is what I tried* <$link to={{!!title}}><$view field="title"/> </$link> <$reveal type="match" state="<$macrocall $name="day-left" bestbefore={{!!bestbefore}} />" text="YES">@@color:red;( to be discarded )@@ </$reveal>but the result of that is not working. Instead it displays:
<$reveal type="match" default=<<day-left bestbefore={{!!bestbefore}}>> text="YES">>
@@color:red;( to be discarded )@@
</$reveal>\define stocks (bestbefore)
<$reveal type="match" default=<<day-left $bestbefore$>> text="YES">
@@color:red;( to be discarded )@@
</$reveal>
\end
<$macrocall $name="stocks" bestbefore={{!!bestbefore}} />
/*\
title: $:/_ppmt/macros/day-left.js
type: application/javascript
module-type: macro
Takes current day and best before date and return their difference in days
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Information about this macro
*/
exports.name = "day-left";
exports.params = [
{name: "bestbefore"}
];
/*
Run the macro
*/
exports.run = function(bestbefore) {
//Make each date object.
var year= parseInt(bestbefore.substring(0,4));
var month= parseInt(bestbefore.substring(4,6));
var day= parseInt(bestbefore.substring(6,8));
var date1 = new Date(year, month, day);
var date2 = new Date();
//Find difference in milliseconds.
var elapsed = date1.getTime()-date2.getTime();
//Number of milliseconds in a day.
var dayMS = 86400000;
//Convert milliseconds to year months and days
var days_diff = Math.floor(elapsed/dayMS);
var result = days_diff;
if (result>10) { return "NO";}
else {return "YES";}
};
})();<$list filter="[!has[draft.of]tag[Stocks]]">
<$set name=bestbefore value={{!!bestbefore}}>
<$link to={{!!title}}><$view field="title"/> </$link> <$reveal type="match" default=<<day-left>> text="YES">
@@color:red;( to be discarded )@@
</$reveal>
<br/>
</$set>
</$list>/*\
title: $:/_ppmt/macros/day-left.js
type: application/javascript
module-type: macro
Takes current day and best before date and return their difference in days
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Information about this macro
*/
exports.name = "day-left";
exports.params = [
{name: "bestbefore"}
];
/*
Run the macro
*/
exports.run = function(bestbefore) {
var bb = this.getVariable("bestbefore") ;
var bestb4 = "" ;
if(bb) bestb4 = bb ;
if(bestbefore) bestb4 = bestbefore ;
//Make each date object.
var year= parseInt(bestb4.substring(0,4));
var month= parseInt(bestb4.substring(4,6));
var day= parseInt(bestb4.substring(6,8));