This page is part of a static HTML representation of the TiddlyWiki at http://tiddlywiki.com/

ActionListopsWidget

28th December 2015 at 8:33am
ActionWidgets Widgets

Introduction

The action-listops widget is an action widget that manipulates user lists in any field or data index. ActionWidgets are used within triggering widgets such as the ButtonWidget.

Content and Attributes

The action-listops widget is invisible. Any content within it is ignored.

AttributeDescription
$tiddlerThe title of the tiddler whose lists are to be modified (if not provided defaults to the current tiddler
$fieldThe name of a field to be manipulated as a list (defaults to 'list')
$indexOptional index of a property in a data tiddler index to be manipulated as a list
$filterAn optional filter expression, the output of which will be saved to the field/index being manipulated
$subfilterAn optional subfilter expression, which takes the list being manipulated as input, and saves the modified list back to the field/index being manipulated
$tagsAn optional subfilter expression, which takes the 'tags' field of the target tiddler as input, and saves the modified list of tags back to the 'tags' field

Extended Filter Operators

A number of extended filter operators are necessary for the manipulation of lists. These operators have been designed primarily for use in subfilter expressions whereby the modified current list is returned in place of the current list.

Listops Operators
Operator Purpose
allafter discard all items except those after the marker
allbefore discard all items except those before the marker
append append a range of items from an array to the list
insertbefore insert an item T into a list immediately before an item B
move move marker N places in the list
prepend prepend a range of items from an array to the list
putafter move N trailing items after the marker
putbefore move N trailing items before the marker
putfirst move N trailing items to the head of the list
putlast move N leading items to the tail of the list
remove remove a list of titles specified in the operand from the input
replace replace marker with N trailing items
sortby sort the current list in the order of the list referenced in the operand

Examples

In this example we shall populate and then clear a list in an ordinary field (myfield) of this tiddler (the default.)

<$button>
<$action-listops $field="myfield" $subfilter="efg hlm pqr"/>
Populate 'myfield'
</$button>
<$button>
<$action-listops $field="myfield" $subfilter="abc xyz"/>
Append More Items
</$button>
<$button>
<$action-listops $field="myfield" $subfilter="-abc -hlm"/>
Remove Items
</$button>
<$button>
<$action-listops $field="myfield" $filter="[[]]"/>
Clear 'myfield'
</$button>

<$list filter="[list[!!myfield]]">

</$list>

That renders as:


In this example we shall append and remove items from a list in an ordinary field (myfield) of this tiddler (the default) and sort the resultant list. We shall then remove some of the appended items and sort the resulting list in reverse order.

<$button>
<$action-listops $field="myfield" $subfilter="-efg ijk xyz [[this is a title]] +[sort[]]"/>
Mangle List
</$button>
<$button>
<$action-listops $field="myfield" $subfilter="-xyz -[[this is a title]] +[!sort[]]"/>
Unmangle List
</$button>

<$list filter="[list[!!myfield]]">

</$list>

That renders as:


In this example we shall append a few tags to the 'tags' field of this tiddler (the default.) We shall then remove some of the appended tags.

<$button>
<$action-listops $tags="+[append{Days of the Week!!short}] $:/tag1 $:/tag2 $:/tag3"/>
Populate 'tags'
</$button>
<$button>
<$action-listops $tags="+[!remove:2{!!tags}]"/>
Remove Last Two Tags
</$button>
<$button>
<$action-listops $tags="+[!prefix[$:/]]"/>
Remove System Tags
</$button>
<$button>
<$action-listops $tags="-Mon -Tue"/>
Remove Mon and Tue
</$button>
<$button>
<$action-listops $tags="+[prefix[$:/]] ActionWidgets Widgets"/>
Remove User Tags
</$button>
<$button>
<$action-listops $tags="+[[]] ActionWidgets Widgets"/>
Clear Tags
</$button>

<$list filter="[list[!!tags]]">

</$list>

That renders as:

ActionWidgets
Widgets