The List Model
The List model is the primary way you'll interact with a user's lists. This model includes all the functions and variables needed to setup a full multi-list setup, and has nice shortcuts for the sub-items and functions within.
Accessing
Getting an array of list models is a simple as a single tag, with no parameters.
{% set lists = craft.shortlist.lists %}
Note: This array could be empty if the user has no lists
This will return an array of the current user's lists.
Variables
Each list model has the following core variables available :
id
Int- The id for this list.
default
Bool- A true/false marker to denote if this list is the user's current default list.
title
String- The title for the list. The default list title is controlled in the Shortlist settings, but can be set by the user if you expose the option
owner
UserModel- The UserModel for the owner of the current list. If the owner is a member this will be the appropriate craft member UserModel. If they are a guest, this will be a bare UserModel instead.
ownerId
Int- The id of the list owner.
ownerType
String- The user type for the owner. Will be either 'Member' or 'Guest' depending on if they're logged in or not.
items
Array, possibly EMPTY- An array of Item models for the items in this list
Actions
Each list has a number of actions that can be permfomed on it - delete, clear and makeDefault
Note: All these actions are just shortcut functions to build up urls like : <br/>'/index.php/{{ actionTrigger }}/shortlist/list/{{ actionType }}?{{ params }}
'<br/> If needed, you can build these up directly. View the available action points
{{ list.makeDefaultActionUrl }}
- An action to make this list the default for the user. Combine with the
{% if list.default %}..{% endif %}
logic to display as needed. When triggered this will first unset the previously default list. {{ list.clearActionUrl }}
- An action to CLEAR the current list. This will remove all the items from a list, but leave the actual list.
{{ list.deleteActionUrl }}
- An action to DELETE the current list. This will remove the current items from the list and then remove the list itself.
Parameters
Each function accepts the following parameters :
return
- Optional alternative return url. If none supplied will default to the current url.
<a href="{{ list.makeDefaultActionUrl({ 'return' : 'wishlist' }) }}">Make Default</a>