1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-01-27 01:14:44 +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} template: {byPos: 2, type: "text", optional: true}
}, },
handler: function(type,tiddler,store,params) { handler: function(type,tiddler,store,params) {
var v = tiddler[params.field], var encoder = type === "text/html" ? utils.htmlEncode : function(x) {return x;};
encoder = type === "text/html" ? utils.htmlEncode : function(x) {return x;}; if(!tiddler) {
if(v) { return "{{** Missing tiddler **}}";
switch(params.format) { } else {
case "link": var v = tiddler[params.field];
return store.renderMacro("link",type,tiddler,{target: v},encoder(v)); if(v !== undefined) {
case "wikified": switch(params.format) {
return store.renderTiddler(type,tiddler.title); case "link":
case "date": return store.renderMacro("link",type,tiddler,{target: v},encoder(v));
var template = params.template || "DD MMM YYYY"; case "wikified":
return encoder(utils.formatDateString(v,template)); return store.renderTiddler(type,tiddler.title);
default: // "text" case "date":
return encoder(v); var template = params.template || "DD MMM YYYY";
return encoder(utils.formatDateString(v,template));
default: // "text"
return encoder(v);
}
} }
} }
return ""; return "";