> I have been interested in recent discussions about slice-related
> plugins.  They seem to be an interesting alternative to FormTiddler
> and DataTiddler Plugins-based use.  But, I am still confused with the
> implementation of such a system; I do better with learning from
> working examples.
> Is there someone who can post a real world example of a slice-based
> TW?


Slices are a TW-native syntax, and therefore don't require any plugins
to use the basic functionality (though, obviously, there are slice-
related plugins that provide enhancements).

Essentially, a 'tiddler slice' is a name-value pair, stored within the
*text* of the tiddler content, using specific forms of TW syntax.

You can define tiddler slices by entering a simple, two-column table
into a tiddler, where the first column of the table contains the names
of the slices, and the second column contains the values:

|name|value|
|name|value|
|name|value|
etc.

Note that, because each row of the TW table syntax is *line-based*, it
means that slice values can only contain one line of text, without any
newlines... otherwise it would 'break' the table syntax.

Use of slice tables is widespread, and can be seen at the top of most
published plugins, scripts, etc., which include a 'slice table' with
certain standardized slice names.  For example, here's the slice table
from TiddlyTools' SliceGridPlugin:

-----------------------------------
|Name|SliceGridPlugin|
|Source|http://www.TiddlyTools.com/#SliceGridPlugin|
|Documentation|http://www.TiddlyTools.com/#SliceGridPluginInfo|
|Version|1.2.0|
|Author|Eric Shulman|
|License|http://www.TiddlyTools.com/#LegalStatements|
|~CoreVersion|2.1.3|
|Type|plugin|
|Requires||
|Overrides||
|Description|Display/edit slices/fields in a grid (table) for a 'birds-
eye' view of your document|
-----------------------------------

Most of the slices in this table are optional, and are provided by
convention, for informational purposes only.  However, a few of the
slices are used programmatically by the TW core, or by various
plugins, or even by some server-side utilities (such as the automatic
TiddlyHub index - see http://plugins.tiddlywiki.org).

Specifically, the "CoreVersion" value is used to indicate the
*minimum* version of the TW core that is required by a plugin in order
for it to operate.  During document startup, if this value is more
recent than the core version in use in that document, then the plugin
will not be loaded (and an 'error' is reported in the
[[PluginManager]]

Similarly, during load time the TW core uses the "Requires" slice to
adjust the normal alphabetic order in which plugins are invoked.  If a
given plugin depends upon one or more functions defined in some other
plugins, then listing those other plugins in the Requires slice tells
the TW core to invoke those plugins first, before invoking the code
from the dependent plugin.

The TW core also uses slices to define 'systemServer' tiddlers, which
can be optionally created to store and re-use the location of remote
TW documents from which you can import other tiddlers when using the
backstage 'import' (or [[ImportTiddlers]]) interface.

For example, here's the entire contents of [[TiddlyToolsServer]] as
found on http://www.TiddlyWiki.com):
-----------------------------------
|''URL:''|http://www.tiddlytools.com/|
|''Description:''|Small Tools for Big Ideas!|
|''Author:''|EricShulman|
-----------------------------------
The URL and Description slices are used in the "select a pre-defined
feed" droplist presented in the import interface, and the Author slice
is provided just for user-readable information.

Of course, defining slices for use by the TW core is only half the
fun!  The other half is using your own custom slice tables to create
and embed simple text 'variables' in your own tiddler content by using
the <<tiddler TiddlerName>> macro to *transclude* single slice
values.  To reference a particular slice in a specific tiddler, you
can write:
   <<tiddler [[TiddlerName::slicename]]>>

For example, you could create a tiddler called [[Abbrevs]], containing
a slice table like this:
-----------------------------------
|CDC|United States Center for Disease Control|
|disease|pneumonoultramicroscopicsilicovolcanoconiosis||
etc.
-----------------------------------
and then write (in another tiddler):
-----------------------------------
The <<tiddler Abbrevs::CDC>> is reporting several recent cases of
<<tiddler Abbrevs::disease>> occurring in people other than coal
miners.
-----------------------------------

... and, with the addition of InlineJavascriptPlugin or
<<forEachTiddler>>, you can retrieve and use slice values
*programmatically* as well, by reference to the TW core function:
   var slicetext=store.getTiddlerSlice("TiddlerName","slicename");

For example, the following inline script generates a listing of all
'systemServer' definition in the document:
-----------------------------------
<script>
   var out=[];
   var tids=store.getTaggedTiddlers('systemServer');
   for (var i=0; i<tids.length; i++) {
      var url=store.getTiddlerSlice(tids[i].title,'URL');
      var desc=store.getTiddlerSlice(tids[i].title,'Description');
      var fmt='| [[%0]]|%1|%2|';
      out.push(fmt.format([tids[i].title,url,desc]);
   }
   return out.join('\n');
</script>
-----------------------------------
which produces TW syntax output that looks like this:
   | [[TiddlerName1]]| http://...|some descriptive text|
   | [[TiddlerName2]]| http://...|some other text|
   | [[TiddlerName3]]| http://...|you get the idea...|
that renders as a nice summary table of information.

These are, of course, only a few of the numerous ways that slices can
be applied in TW documents.  I'm sure that once you start
expermenting, you'll quickly come up with several other use-cases that
fit your particular purposes.

enjoy,
-e
Eric Shulman
TiddlyTools / ELS Design Studios
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To post to this group, send email to tiddlywiki@googlegroups.com
To unsubscribe from this group, send email to 
tiddlywiki+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/tiddlywiki?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to