The Item Model
The Item Model is the primary way you'll interact with items when using Shortlist. This model includes functions for all the main item operations, and variables and helpers for all the various state and data actions you'll need.
Accessing
Getting an item model is simple. Use the shortlist.item variable, along with the elementId of the element in question.
{% set item = craft.shortlist.item(entry.id) %}
Note: An item model doesn't nessecarily indicate an element is in a user's list. You can pull a bare item model for an element, which will is basically an item that doesn't exist in a list yet.
Variables
Each item model has a set of core variables available :
id
Int or NULL- The id for this item. Will be null if this item is a bare item.
inList
Bool- A true/false variable to denote if this item is in the user's list.
Note: This follows the context of the list being viewed. If not in a specific list view, will refer to the default list context
elementId
Int- The elementId of the Id related to this item. Eg. '14'
elementType
String- The elementType of the related element. Eg. 'entry' or 'user' etc..
listId
Int or NULL- The id of the List for this item. May return
NULL
if the user has no current lists. (A list will be automatically created when an item is first added in this case) otherLists
Array ofShortlist_ItemModel
, possibly EMPTY- An array of items, all with the current element, but in the context of the other lists for the current user. This array excludes the current default list.
lists
Array, possibly EMPTY- An array of items, all with the current element, but in the context of the all lists for the current user. This array includes the current default list.
title
String- The title of the parent element. ie. 'Entry One', useful when used in the context of the List array
element
ElementModel- The element model for the parent element. ie. if this is an entry, this will be the EntryModel. This is exactly the same as if you'd used the normal craft.entries.. tags to retrieve the element. Useful in the context of the List array eg :
{{ item.title }} by {{ item.element.author }}, {{ item.element.someOtherField }}
parentList
Shortlist_ListModel, possibly NULL- The List model for the parent list. Will return a List model which can be used to access all the variables and functions on the parent list.
Actions
Each item has a number of actions that can be performed. Basically this are the obvious add/remove actions, but do cover other utility actions.
Note: All these actions are just shortcut functions to build up urls like : <br/>'/index.php/{{ actionTrigger }}/shortlist/item/{{ actionType }}?{{ params }}
'<br/> If needed, you can build these up directly. View the available action points
Functions
{{ item.addActionUrl }}
- The main ADD action. Adds this element directly the list from the current context. If none supplied, will add to the default list.
{{ item.removeActionUrl }}
- The main REMOVE action. Removes this element directly the list from the current context. If none supplied, will add to the default list.
{{ item.toggleActionUrl }}
- The main TOGGLE action. This is a bi-directional version of the add/remove action. Will add the item if in the current context list, or remove if it's already in the list. Especially useful for ajax implementations as this will stay consistent across user interaction.
Parameters
Each function accepts the following parameters :
return
- Optional alternative return url. If none supplied will default to the current url.
<a href="{{ item.addActionUrl({ 'return' : 'wishlist' }) }}">Add Item</a>