@tiddlywiki plugin – treating sections and slices as fields

12 Feb

@jermolene's generally encouraged me to use sections and slices instead of fields, being that they are more free-form, hence more tiddlyesque. This isn't always easy, because fields have better editing support. (Although the "edit" macro is sort of buggy, because it prevents you clicking on edit to edit the underlying text.)

One step in this direction is to hijack store.getValue as shown below. It's used by the "view" macro – which appears in view/edit templates – to render tiddler fields. Use the following plugin code (currently in Scrumptious's zzScrumptious.js, I might extract it later) and "view" will let you render slices and sections. So if your ViewTemplate includes:

?? <div class='bookmarkDescription' macro='view Description wikified'></div>

It will show a "Description" section if there is one, and if not, a Description slice, and if not, the Description field, if that exists.

You would normally only use this for a highly-customised tiddler view in which the "text" field (the main stuff of the tiddler) is not actually shown, i.e. you've removed from the standard View template the line ?? <div class='bookmarkDescription' macro='view Description wikified'></div>.

?? _getValue = store.getValue;
?? store.getValue = function(tiddler, field, value) {
?????? var sectionContent, slice, tiddler = store.resolveTiddler(tiddler);
?????? sectionContent = store.getTiddlerText(tiddler.title+"##"+field);
?????? console.log(tiddler.title, field, "nooot", sectionContent);
?????? if (sectionContent) return sectionContent;
?????? if (sliceContent?? = store.getTiddlerText(tiddler.title+"::"+field)) return sliceContent;
?????? return _getValue.apply(this, arguments);
?? }


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: