diff --git a/editions/tw5.com/tiddlers/demonstrations/NestedLists.tid b/editions/tw5.com/tiddlers/demonstrations/NestedLists.tid new file mode 100644 index 000000000..694aac663 --- /dev/null +++ b/editions/tw5.com/tiddlers/demonstrations/NestedLists.tid @@ -0,0 +1,45 @@ +title: NestedLists +tags: ListWidget +created: 20150106180000000 +modified: 20150106180000000 + + +The following sidebar tabs give examples of grouped lists created by nesting. + +!! Types Tab + +The list in the [[Types|$:/core/ui/MoreSideBar/Types]] tab is generated with this markup: + +``` +<$list filter="[!is[system]has[type]each[type]sort[type]]"> +
+<$view field="type"/> +<$list filter="[type{!!type}!is[system]sort[title]]"> +
+<$link to={{!!title}}><$view field="title"/> +
+ +
+ +``` + +The outer list filter selects each discrete value found in the `type` field. The inner list filter selects all the (non-system) tiddlers with that type. + +!! Recent Tab + +The list in the [[Recent|$:/core/ui/SideBar/Recent]] tab is generated with this markup: + +``` +<$list filter="[!is[system]has[modified]!sort[modified]limit[100]eachday[modified]]"> +
+<$view field="modified" format="date" template="DDth MMM YYYY"/> +<$list filter="[sameday{!!modified}!is[system]!sort[modified]]"> +
+<$link to={{!!title}}><$view field="title"/> +
+ +
+ +``` + +Here, the outer list filter selects each discrete day found in the `modified` field, while the inner list filter selects all the tiddlers dated the same day in the `modified` field. \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/variables/IteratorVariables b/editions/tw5.com/tiddlers/variables/IteratorVariables new file mode 100644 index 000000000..d88f54e65 --- /dev/null +++ b/editions/tw5.com/tiddlers/variables/IteratorVariables @@ -0,0 +1,91 @@ +title: IteratorVariables +tags: ListWidget Variables +created: 20150106180000000 +modified: 20150106180000000 + +The ListWidget exposes the following iterator variables during list processing: + +; `<>` +: set to the current index, e.g. `1` +; `<>` +: set to `true` for an even index, otherwise `false` +; `<>` +: set to `true` for last index, otherwise `false` + +The ListWidget allows to declare an `iterator` attribute through which you can declare a custom iterator variable prefix: + +``` +<$list filter="[tag[foo]]" iterator="my-foo"> +... + +``` + +!!Using Iterator Variables + +You can use iterator variables with the RevealWidget to conditionally render output depending on the current index... + +''only show for item at index 1, i.e. the first item'' + +``` +<$reveal type=match default=1 text=<>> +... + +``` + +''show for all except first index'' + +``` +<$reveal type=nomatch default=1 text=<>> +... + +``` + +''only show at even indexes'' + +``` +<$reveal type=match default=true text=<>> +... + +``` + +''only show at uneven indexes'' + +``` +<$reveal type=nomatch default=true text=<>> +... + +``` + +''only show for last index'' + +``` +<$reveal type=match default=true text=<>> +... + +``` + +!! Live Example + +``` +
+<$list filter="one two three" iterator=foo> +
<>
+
`<>` = <>
+
`<>` = <>
+
`<>` = <>
+ +
+``` + +Displays as: + +<<< +
+<$list filter="one two three" iterator=foo> +
<>
+
`<>` = <>
+
`<>` = <>
+
`<>` = <>
+ +
+<<< \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/widgets/ListWidget.tid b/editions/tw5.com/tiddlers/widgets/ListWidget.tid index 07a745e06..7bb88cbce 100644 --- a/editions/tw5.com/tiddlers/widgets/ListWidget.tid +++ b/editions/tw5.com/tiddlers/widgets/ListWidget.tid @@ -1,36 +1,85 @@ created: 201310241419 -modified: 20141027193838998 +modified: 20150106180000000 tags: Widgets title: ListWidget caption: list ! Introduction -The list widget displays a sequence of tiddlers that match a [[tiddler filter|Filters]]. It can be used for many purposes: +The list widget displays a sequence of tiddlers matching a [[filter|Filters]]. It is vital for a various use-cases, e.g.: -* Displaying custom lists of links, like in TiddlyWiki5's sidebar -* Custom lists, such as "all tiddlers tagged 'task' that are not tagged 'done'" -* Listing each of the tags applied to a tiddler +* Displaying custom lists, e.g. "all tiddlers tagged ''task'' not tagged ''done''" +* Listing the tags of a tiddler +* Displaying lists of links, like in the sidebar * Handling the main story river -The tiddlers are displayed by transcluding each in turn through a template. There are several ways to specify the template and for controlling the behaviour of the list. +! Examples + +''plain list'' + +``` +<$list filter="[tag[ListWidget]sort[title]]"/> +``` + +Displays as: + +<<< +<$list filter="[tag[ListWidget]sort[title]]"/> + +<<< + +''custom item output'' + +``` +<$list filter="[tag[ListWidget]sort[title]]"> +<> +{{||$:/core/ui/ViewTemplate/tags}} + +``` + +Displays as: + +<<< +<$list filter="[tag[ListWidget]sort[title]]"> +<> +{{||$:/core/ui/ViewTemplate/tags}} + +<<< + +''custom item template'' + +``` +<$list filter="[tag[ListWidget]sort[title]]" template="$:/core/ui/ViewTemplate/subtitle"/> +``` + +Displays as: + +<<< +<$list filter="[tag[ListWidget]sort[title]]" template="$:/core/ui/ViewTemplate/subtitle"/> + +<<< + +!! Grouped Lists + +See NestedLists for how to generate nested and grouped lists using the ListWidget. ! Content and Attributes -The content of the `<$list>` widget is an optional template to use for rendering each tiddler in the list. Alternatively, the template can be specified as a tiddler title in the ``template`` attribute. As a fallback, the default template just displays the tiddler title. +A number of options controll the list behaviour.... |!Attribute |!Description | |filter |The [[tiddler filter|Filters]] to display | -|template |The title of a template tiddler for rendering each tiddler in the list | -|editTemplate |An alternative template to use for DraftTiddlers in edit mode | -|variable |The [[widget variable|WidgetVariables]] name to be assigned the title of each tiddler in the list. Defaults to ''currentTiddler'' | +|template |The title of a template tiddler for transcluding each tiddler in the list. When no template is specified, the body of the ListWidget serves as the item template. With no body, a simple link to the tiddler is returned. | +|editTemplate |An alternative template to use for [[DraftTiddlers|DraftMechanism]] in edit mode | +|variable |The name for a [[variable|Variables]] in which the title of each listed tiddler is stored. Defaults to ''currentTiddler'' | +|iterator|a custom iterator prefix, see IteratorVariables| |emptyMessage |Message to be displayed when the list is empty | |storyview |Optional name of module responsible for animating/processing the list | |history |The title of the tiddler containing the navigation history | -!! Handling edit mode +!! Edit mode -The `<$list>` widget can optionally render draft tiddlers through a different template tiddler than ordinary tiddlers -- see DraftMechanism for a discussion of how this capability is used. +The `<$list>` widget can optionally render draft tiddlers through a different template to handle editing, see DraftMechanism. !! `storyview` attribute @@ -42,48 +91,6 @@ The `storyview` attribute specifies the name of an optional module that can anim In order for the storyviews to animate correctly each entry in the list should be a single block mode DOM element. -!! Handling history and navigation - -The optional `history` attribute specifies the name of a tiddler that is used to track the current tiddler for navigation purposes. When the history tiddler changes the list view responds by telling the listview to handle navigating to the new tiddler. See the NavigationMechanism for more details. - -! Examples - -!! Creating nested lists - -The ''types'' and ''recent'' tabs in the sidebar give two examples of a grouped list created by nesting. - -The ''types'' listing is performed with this markup: - -``` -<$list filter="[!is[system]has[type]each[type]sort[type]]"> -
-<$view field="type"/> -<$list filter="[type{!!type}!is[system]sort[title]]"> -
-<$link to={{!!title}}><$view field="title"/> -
- -
- - -``` - -The outer list filter selects each discrete value found in the `type` field. The inner list filter selects all the (non-system) tiddlers with that type. - -The ''recent'' listing is performed with this markup: - -``` -<$list filter="[!is[system]has[modified]!sort[modified]limit[100]eachday[modified]]"> -
-<$view field="modified" format="date" template="DDth MMM YYYY"/> -<$list filter="[sameday{!!modified}!is[system]!sort[modified]]"> -
-<$link to={{!!title}}><$view field="title"/> -
- -
- -``` - -Here the outer list filter selects each discrete day found in the `modified` field, while the inner list filter selects all the tiddlers dated the same day in the `modified` field. +!! History and navigation +The optional `history` attribute specifies the name of a tiddler that is used to track the current tiddler for navigation purposes. When the history tiddler changes the list view responds by telling the listview to handle navigating to the new tiddler. See HistoryMechanism for details. \ No newline at end of file