Variables
Shortlist has 2 core variables which you'll be using. shortlist.item
and shortlist.lists
The Main Variables
shortlist.item
- Gets all the info about a specific item. The tag used to handle the add/remove buttons
shortlist.lists
- Gets all the info about a user's lists. Includes sub arrays of items within to those lists.
Helper Variables
shortlist.itemCount
New in 1.1- A quick count for how many items a user has in all their lists
shortlist.newListActionUrl
- A helper function for building a 'New List' link.
shortlist.error
- A helper function to return a possible error message after a failed action
shortlist.item
Gets all the info about a specific item. This can be any element in Craft - entries, assets, users, tags, or any custom ElementType.
Parameters
ElementId
*required- The element id of the current item. This is the id of the entry/user/asset etc..
{% set item = craft.shortlist.item(entry.id) %}
Returns
Shortlist_ItemModel
- With all the current item data populated.
Note: This item might be a bare version if the item isn't actually in a user's list. Functionally the same, but some values will be null
Options and Usage for Shortlist_ItemModel →
shortlist.lists
Gets all the lists for the current user.
Parameters
None
{% set lists = craft.shortlist.lists() %}
Returns
Array
ofShortlistListModel
OREMPTY
- Will return a full array of all the current lists for the current user. Each list in the array is it's own
ShortlistListModel
, and each of those have all the associated helper functions and data about the contents. If the user has no current lists, will return an empty array.
Options and Usage for Shortlist_ListModel →
shortlist.itemCount New in 1.1
A helper function to get the count of all the items in a user's lists.
Parameters
None
Returns
String
- the count of items- Eg. '3' - there are 3 items across the user's lists.
Usage
{% if craft.shortlist.itemCount > 0 %} Your Items.. {% else %} You have no items yet {% endif %}
shortlist.newListActionUrl
A helper function to create a 'New List' link
Parameters
Return
- Optional, a return url for the action. If not supplied will default to the current url.
Returns
String
- the generated new list url- Will be of the form : <br/>
/index.php/action/shortlist/new?return=..
Usage
<a href="{{ craft.shortlist.newListActionUrl({ 'return' : 'account/lists' }) }}">+ New List</a>
Which will return similar to :
<a href="action/..">+ New List</a>
shortlist.error
A helper function to return a specific error reason after a failed action.
See more about error handling with Shortlist.
Parameters
None
Returns
String
orNULL
- the fully rendered error message- Returns the specific error message for the issue encountered. It's possible for multiple errors to be encountered in the same request, in which case the errors will be returned marked up within an <ul>..</ul>
Usage
{% if craft.shortlist.error %} <div class="alert alert-error"> {{ craft.shortlist.error }} </div> {% endif %}