{previous:ids:current_id}

Description

Returns the id that comes immediately before current_id in a dash-separated list of ids. Use it to build a backward (Previous) link on a detail page: feed a list of item ids and the id of the item being shown, and previous gives you the id of the preceding item. The list is usually a query result from ids, but any dash-separated list works (the values need not be ids). Returns an empty string when current_id is the first entry, is not found in the list, or when either argument is empty - so a Previous link naturally disappears on the first item. The list is split on the dash and empty segments from a doubled or trailing dash are dropped, which can break the lookup; keep the separators clean. The mirror command next returns the id after current_id.

Parameters

ids required

Dash-separated list of ids (or any values) to step through, in order. Usually the output of {ids:...} - a query result - but any dash-separated string works. Empty segments from a doubled or trailing dash are dropped and can shift positions, so keep the separators clean.

current_id required

The id whose predecessor you want, taken from the ids list. It must be the same id type (long or short) as the entries in ids. If current_id is the first entry, is not found in the list, or is empty, previous returns an empty string.

Examples

test{previous:12-34-56:34}
Expected12
Actual12
The basic shape. Given a dash-separated list and the current value 34, previous returns the value that comes before it, 12.
test{previous:alpha-beta-gamma-delta:gamma}
Expectedbeta
Actualbeta
The entries do not have to be ids - previous steps through any dash-separated list. The value before gamma is beta.
test{previous:12-34-56:12}
When current_id is the first entry in the list, previous returns an empty string. This is how a Previous link hides itself on the first item.
test{previous:12-34-56:99}
If current_id is not found in the list, previous returns an empty string (it does not guess or return the last item).
test{previous:{ids:9e1d2b9f88e3d6c3bf0eb967378610d6}:4f3362a62847fe1f8c59ba28a92d42c0}
Expected5726c2c6b035d7aab450d1794e9e90d7
Actual5726c2c6b035d7aab450d1794e9e90d7
The everyday pattern: feed a queried set straight into previous. {ids:...} returns the ids of a slice in display order, and previous gives the id that precedes the current one - here the id of the item shown before 4f3362a62847fe1f8c59ba28a92d42c0.
test{previous:12--56:56}
A doubled dash leaves an empty segment, which previous drops while keeping the original positions. That leaves a gap right before 56, so previous finds nothing and returns empty. Keep the separators clean - usually the list comes straight from {ids:...}.
test{iftext:{previous:12-34-56:34}:Previous is {previous:12-34-56:34}:no previous}
ExpectedPrevious is 12
ActualPrevious is 12
The detail-page idiom, made concrete. iftext prints its middle branch only when the condition is non-empty, so a Previous link shows only when a preceding item exists. On the first item previous returns empty and the link disappears.