Any examples of actual slice use?

171 views
Skip to first unread message

AlanBCohen

unread,
Sep 20, 2009, 8:42:37 AM9/20/09
to TiddlyWiki
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?

Thank you,
Alan

Eric Shulman

unread,
Sep 20, 2009, 10:36:04 AM9/20/09
to TiddlyWiki
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

AlanBCohen

unread,
Sep 20, 2009, 1:53:13 PM9/20/09
to TiddlyWiki
Thanks, Eric,
You've given me a lot to think about.
Alan

AlanBCohen

unread,
Sep 20, 2009, 10:24:53 PM9/20/09
to TiddlyWiki
Here is my first attempt to use slices in an application. The
retrieval isn't working. Based on Eric's information, I'm guessing I
have a typo in the retrieval tiddler. I'd appreciate some help in
correcting it.
First, I'm defining data tiddlers with the tag of 'address', with a
structure like (without the {{{}}}):
{{{First: Alan
Last: Cohen
Middle: B.
Street: 123 Main St.
City: Somewhere
State: HI
Postal: 12345
Phone1: xxx-xxx-xxxx
Email1: m...@myisp.edu}}}

Then, I'm trying to product a list of first and last names, sorted by
last name using a tiddler with:

<<forEachTiddler
where
'tiddler.tags.contains("address")'
sortBy
'tiddler.title::Last'
ascending
write
'"|"+tiddler.title::First+"|"+tiddler.title::Last+"|"+tiddler.tags
+"|\n"'
>>

The error message is 'ReferenceError: title is not defined'

AlanBCohen

unread,
Sep 20, 2009, 10:34:04 PM9/20/09
to TiddlyWiki
I should also make clear that the forEachTiddlerPlugin is installed
and working to produce other lists in this TW file.

Eric Shulman

unread,
Sep 21, 2009, 12:23:30 AM9/21/09
to TiddlyWiki
> <<forEachTiddler
>  where
>     'tiddler.tags.contains("address")'
>  sortBy
>    'tiddler.title::Last'
>    ascending
>  write
>    '"|"+tiddler.title::First+"|"+tiddler.title::Last+"|"+tiddler.tags
> +"|\n"'

To render a slice value using TW wiki syntax, you can write:
<<tiddler [[TiddlerName::slicename]]>>

To programmatically retrieve the value of a slice, use:
store.getTiddlerText("TiddlerName::slicename","");
(note: the 2nd param is the default text to use if the tiddler
slice does not exist)

Thus, for your use-case:

<<forEachTiddler
where
'tiddler.tags.contains("address")'
sortBy
'store.getTiddlerText(tiddler.title+"::Last","")'
ascending
write
'"|"+store.getTiddlerText(tiddler.title+"::First","")
+"|"+store.getTiddlerText(tiddler.title+"::Last","")+"|"+tiddler.tags
+"|\n"'

enjoy,
-e

AlanBCohen

unread,
Sep 21, 2009, 6:37:23 AM9/21/09
to TiddlyWiki
Thanks again, Eric. I'll play with this when I get home tonight.
Alan

Mike

unread,
Sep 21, 2009, 5:37:18 PM9/21/09
to TiddlyWiki
I don't have much time, but you may be able to find some good examples
here:
http://www.strm.us/TidlyWiki/Examples_TWGG/fETTaskManager.html

The other examples in the following link give some good
InlineJavascript examples to do the same.

http://groups.google.com/group/tiddlywiki/browse_thread/thread/d2d3a885facaa654/fde60b419a07c1f3#fde60b419a07c1f3

Hope that helps,

Mike

wolfgang

unread,
Sep 21, 2009, 7:40:18 PM9/21/09
to TiddlyWiki
An other default use of is with the color slices of the ColorPalette
shadowed tiddler.
Or as in this special case, where the author uses the ColorPalette for
background images too (switching different images with a color palette
change):

http://mwanz.tiddlyspot.com/#ColorPalette

Regards..

AlanBCohen

unread,
Sep 21, 2009, 10:27:20 PM9/21/09
to TiddlyWiki
Thanks to Mike and Wolfgang for their additional information.
Alan

lyallp

unread,
Sep 22, 2009, 8:04:05 AM9/22/09
to TiddlyWiki
I also whipped up a Slice plugin....

http://www.remotely-helpful.com/TiddlyWiki/ImprovedSlicesPlugin.html#ImprovedSlicesPlugin

I use it all the time in my own tiddlywiki, an example is as follows,
in conjunction with my Encryption Plugin (http://www.remotely-
helpful.com/TiddlyWiki/TiddlerEncryptionPlugin.html)

I encrypt the WebSiteNameLoginPassword tiddler, using the encryption
plugin. If I don't decrypt, the WebSiteNameLoginId tiddler does not
show passwords.

So, I can pass around my tiddlywiki and if I don't hand out the
password, people can see the sites I use but not the usernames or
passwords.

I use includes elsewhere as well, but this is the main one.


Tiddler name: WebSiteNameLoginId
--------------------------------------------
|!Company:|SiteNamel|>|>|
|!Site:|http://www.site.url.com|>|>|
|!Authentication:|<<tiddler "WebSiteNameLoginPassword::Login01">>|
<<tiddler "WebSiteNameLoginPassword::Login01+1#1">>|<<tiddler
"WebSiteNameLoginPassword::Login01+3#1">>|
|!Authentication:|<<tiddler "WebSiteNameLoginPassword::Login02">>|
<<tiddler "WebSiteNameLoginPassword::Login02+1#1">>|<<tiddler
"WebSiteNameLoginPassword::Login02+3#1">>|
|!Notes:|This is a demo site.|>|>|

Set password in WebSiteNameLoginPassword
--------------------------------------------

Tiddler name: "WebSiteNameLoginPassword"
--------------------------------------------
|!Slice|!User|!Password|!Last Changed|!Notes|
|Login01|username|aPassword|12/09/2009||
|Login02|secondUsername|AnotherPassword|12/09/2009||
--------------------------------------------

...Lyall

wolfgang

unread,
Sep 22, 2009, 8:13:57 AM9/22/09
to TiddlyWiki
> --------------------------------------------
> |!Slice|!User|!Password|!Last Changed|!Notes|
> |Login01|username|aPassword|12/09/2009||
> |Login02|secondUsername|AnotherPassword|12/09/2009||
> --------------------------------------------
>

How nice would be if the now to GridPlugin renamed SliceGridPlugin -
be able to recognize and edit such multi column tables inline..

http://www.tiddlytools.com/#GridPluginInfo

:-)

Simon Baird

unread,
Nov 10, 2009, 7:25:26 AM11/10/09
to tiddl...@googlegroups.com
On the topic of things that use slices...

MPTW can display tiddler slices in tagging lists. For example go to the link below and click 'slices'. It's one of the small buttons above the list. You can do a neat contacts list in this way.
http://mptw.tiddlyspot.com/#systemConfig

--
simon...@gmail.com
Reply all
Reply to author
Forward
0 new messages