1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-02-22 22:10:03 +00:00

Extend makeTranscludeWidget

Add support for specifying the filename, and the fallback content
within the transclude widget that is used if the transclusion target
isn’t found
This commit is contained in:
Jermolene 2014-07-04 21:03:11 +01:00
parent 3ff7462afd
commit c9d4714e98

View File

@ -856,19 +856,30 @@ exports.makeWidget = function(parser,options) {
/* /*
Make a widget tree for transclusion Make a widget tree for transclusion
title: target tiddler title title: target tiddler title
options: as for wiki.makeWidget() (including parseAsInline) options: as for wiki.makeWidget() plus:
options.field: optional field to transclude (defaults to "text")
options.children: optional array of children for the transclude widget
*/ */
exports.makeTranscludeWidget = function(title,options) { exports.makeTranscludeWidget = function(title,options) {
options = options || {}; options = options || {};
var parseTree = {tree: [{ var parseTree = {tree: [{
type: "transclude", type: "element",
attributes: { tag: "div",
tiddler: { children: [{
name: "tiddler", type: "transclude",
type: "string", attributes: {
value: title}}, tiddler: {
isBlock: !options.parseAsInline} name: "tiddler",
type: "string",
value: title}},
isBlock: !options.parseAsInline}]}
]}; ]};
if(options.field) {
parseTree.tree[0].children[0].attributes.field = {type: "string", value: options.field};
}
if(options.children) {
parseTree.tree[0].children[0].children = options.children;
}
return $tw.wiki.makeWidget(parseTree,options); return $tw.wiki.makeWidget(parseTree,options);
}; };