From 1b620387dda2d16bf387a89071188762455890c4 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Wed, 22 Oct 2014 14:12:49 +0100 Subject: [PATCH] Extend the view widget to work with subtiddlers --- core/modules/widgets/view.js | 10 ++++++++-- editions/tw5.com/tiddlers/widgets/ViewWidget.tid | 14 +++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/core/modules/widgets/view.js b/core/modules/widgets/view.js index 6d12ac162..13dc0fdb0 100755 --- a/core/modules/widgets/view.js +++ b/core/modules/widgets/view.js @@ -46,6 +46,7 @@ Compute the internal state of the widget ViewWidget.prototype.execute = function() { // Get parameters from our attributes this.viewTitle = this.getAttribute("tiddler",this.getVariable("currentTiddler")); + this.viewSubtiddler = this.getAttribute("subtiddler"); this.viewField = this.getAttribute("field","text"); this.viewIndex = this.getAttribute("index"); this.viewFormat = this.getAttribute("format","text"); @@ -95,9 +96,14 @@ ViewWidget.prototype.getValue = function(options) { if(this.viewIndex) { value = this.wiki.extractTiddlerDataItem(this.viewTitle,this.viewIndex); } else { - var tiddler = this.wiki.getTiddler(this.viewTitle); + var tiddler; + if(this.viewSubtiddler) { + tiddler = this.wiki.getSubTiddler(this.viewTitle,this.viewSubtiddler); + } else { + tiddler = this.wiki.getTiddler(this.viewTitle); + } if(tiddler) { - if(this.viewField === "text") { + if(this.viewField === "text" && !this.viewSubtiddler) { // Calling getTiddlerText() triggers lazy loading of skinny tiddlers value = this.wiki.getTiddlerText(this.viewTitle); } else { diff --git a/editions/tw5.com/tiddlers/widgets/ViewWidget.tid b/editions/tw5.com/tiddlers/widgets/ViewWidget.tid index e7d11bf55..9d27945e6 100644 --- a/editions/tw5.com/tiddlers/widgets/ViewWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/ViewWidget.tid @@ -1,6 +1,6 @@ title: ViewWidget created: 201310241419 -modified: 201402220837 +modified: 20141022131222150 tags: Widgets caption: view @@ -18,6 +18,7 @@ The content of the `<$view>` widget is displayed if the field or property is mis |index |The name of the index to view | |format |The format for displaying the field (see below) | |template |The optional template used with certain formats | +|subtiddler |Optional SubTiddler title when the target tiddler is a [[plugin|Plugins]] (see below) | !! Formats @@ -31,3 +32,14 @@ The following formats can be specified in the `format` attribute: |''relativedate'' |The field is interpreted as a UTC date and displayed as the interval from the present instant | |''stripcomments'' |The field is interpreted as JavaScript source code and any lines beginning `\\#` are stripped | |''jsencoded'' |The field is displayed as a JavaScript encoded string | + +! SubTiddler Access + +The view widget allows access to the individual tiddlers stored within a [[plugin|Plugins]]. + +The following example will view the core version of the tiddler [[$:/DefaultTiddlers]] even if it has been overridden: + +< + +'>>