1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-01-11 09:50:27 +00:00

Fixed view macro to check whether the tiddler exists

This commit is contained in:
Jeremy Ruston 2012-01-23 16:42:12 +00:00
parent 82a37d3ab4
commit c185989ca5

View File

@ -18,19 +18,23 @@ exports.macro = {
template: {byPos: 2, type: "text", optional: true}
},
handler: function(type,tiddler,store,params) {
var v = tiddler[params.field],
encoder = type === "text/html" ? utils.htmlEncode : function(x) {return x;};
if(v) {
switch(params.format) {
case "link":
return store.renderMacro("link",type,tiddler,{target: v},encoder(v));
case "wikified":
return store.renderTiddler(type,tiddler.title);
case "date":
var template = params.template || "DD MMM YYYY";
return encoder(utils.formatDateString(v,template));
default: // "text"
return encoder(v);
var encoder = type === "text/html" ? utils.htmlEncode : function(x) {return x;};
if(!tiddler) {
return "{{** Missing tiddler **}}";
} else {
var v = tiddler[params.field];
if(v !== undefined) {
switch(params.format) {
case "link":
return store.renderMacro("link",type,tiddler,{target: v},encoder(v));
case "wikified":
return store.renderTiddler(type,tiddler.title);
case "date":
var template = params.template || "DD MMM YYYY";
return encoder(utils.formatDateString(v,template));
default: // "text"
return encoder(v);
}
}
}
return "";