1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-05-04 16:34:10 +00:00

Extend the transclude widget to fallback to displaying it's child nodes if the target isn't defined

This commit is contained in:
Jermolene 2014-02-12 21:38:37 +00:00
parent b5225f5ca8
commit ca0c352278
3 changed files with 8 additions and 5 deletions

View File

@ -62,7 +62,7 @@ TranscludeWidget.prototype.execute = function() {
this.transcludeField, this.transcludeField,
this.transcludeIndex, this.transcludeIndex,
{parseAsInline: parseAsInline}), {parseAsInline: parseAsInline}),
parseTreeNodes = parser ? parser.tree : []; parseTreeNodes = parser ? parser.tree : this.parseTreeNode.children;
// Construct the child widgets // Construct the child widgets
this.makeChildWidgets(parseTreeNodes); this.makeChildWidgets(parseTreeNodes);
}; };

View File

@ -789,13 +789,16 @@ exports.parseTextReference = function(title,field,index,options) {
var tiddler,text; var tiddler,text;
if(field) { if(field) {
tiddler = this.getTiddler(title); tiddler = this.getTiddler(title);
text = tiddler ? tiddler.fields[field] : ""; if(!tiddler || !tiddler.hasField(field)) {
if(text === undefined) { return null;
text = "";
} }
text = tiddler.fields[field];
return this.parseText("text/vnd.tiddlywiki",text.toString(),options); return this.parseText("text/vnd.tiddlywiki",text.toString(),options);
} else if(index) { } else if(index) {
text = this.extractTiddlerDataItem(title,index,""); text = this.extractTiddlerDataItem(title,index,"");
if(text === undefined) {
return null;
}
return this.parseText("text/vnd.tiddlywiki",text,options); return this.parseText("text/vnd.tiddlywiki",text,options);
} }
} }

View File

@ -19,7 +19,7 @@ The TranscludeWidget dynamically imports content from another tiddler.
|tooltip |Tooltip to be added to the generated elements | |tooltip |Tooltip to be added to the generated elements |
|mode |Override the default parsing mode for the transcluded text to "block" or "inline" | |mode |Override the default parsing mode for the transcluded text to "block" or "inline" |
The TranscludeWidget ignores any contained content. The TranscludeWidget treats any contained content as a fallback if the target of the transclusion is not defined (ie a missing tiddler or a missing field).
! Parsing modes ! Parsing modes