{pull}
Iterates a stored sequence, optionally through plays and actions.
Syntax
{pull 'store'} ... {/pull}
{pull} ... {/pull}
{pull:store} ... {/pull:store}
{pull 'store', reverse, first=3} ... {/pull}
{pull 'store', keep, prime} ... {/pull}
Parameters
-
store -
The name a sequence was stored under with
push=orname=. Left out: the sequence pushed last.
Options
-
action -
Any sequence action written as an option (or named with
action='last|2'), applied to the stored values in the order written:reverse,sort,sum,first=3,last=3,append='other', ...shift=nandpop=nalso take the values out of the store. -
keep -
A play with a type:
keep, primeorkeep='prime'keeps the members, and likewiseremove,flagandmake.
Description
{pull 'primes'} ... {/pull} iterates a sequence stored earlier by {sequence} with push='primes' (or name='primes'). The current value is {$sequence}, as in any sequence run. Without a name it takes the sequence that was pushed last. The prefix spelling {pull:primes} ... {/pull:primes} names the store in the tag itself, and a store can even be iterated by its own name: {primes}.
Everything a sequence run can do to its values works here, on the stored values: actions (reverse, sort, sum, first=3, append='other', ...) and plays (keep, even, flag, prime, make, add=4). The store itself is left as it is, except by the actions that take values out of it: shift=2 shows the first two and removes them from the store, pop=2 the last two. To rewrite a store, use {resume}.
Under the strict check pulling a store that was never pushed is an error - there is no stored sequence named 'x', or nothing has been pushed for {pull} without a name. A store is a value of the request: it lives as long as the request does.
Examples
Store once, read twice
The squares are generated once and pulled as they are and reversed.
{sequence square, rows=6, push='squares'}
<p>{pull 'squares'}{$sequence} {/pull}</p>
<p>{pull 'squares', reverse}{$sequence} {/pull}</p>
<p>{pull:squares sum}Sum: {$sequence}{/pull:squares}</p>
1 4 9 16 25 36
36 25 16 9 4 1
Sum: 91
Plays over a store
The same twelve numbers kept, removed and flagged against the type even.
{sequence '1..12', push='dozen'}
<p>keep: {pull 'dozen', keep, even}{$sequence} {/pull}</p>
<p>remove: {pull 'dozen', remove, even}{$sequence} {/pull}</p>
<p>flag: {pull 'dozen', flag, even}{$sequence}{/pull}</p>
keep: 2 4 6 8 10 12
remove: 1 3 5 7 9 11
flag: 010101010101
Taking values out
shift=2 shows the first two values and removes them from the store; the next pull starts at 3.
{sequence '1..6', push='queue'}
<p>Taken: {pull 'queue', shift=2}{$sequence} {/pull}</p>
<p>Left: {pull 'queue'}{$sequence} {/pull}</p>
Taken: 1 2
Left: 3 4 5 6
See also
- {sequence} Generates a range, a list or one of 80 mathematical sequences, and iterates its values.
- {resume} Transforms the sequence pushed last, in place, through an action or a play.
- {action} Runs one sequence action - reverse, sum, first and the rest - over a store, a range or a type, and iterates the result.
- {keep} Keeps only the values of a sequence that belong to a sequence type.