Actions
Quick Jump :
Item Actions - Add, Remove, Toggle
List Actions - Create, Delete, MakeDefault, Clear, ClearAll, DeleteAll
Craft's interactions are based around action routes. These have a form similar to :
action/{{ pluginClass }}/{{ pluginMethod }}?{{ extraParams }}
To make your life easier Shortlist includes helper functions for generating all these action urls, however you are free to build up your own action urls if you need.
For reference, the actions available for Shortlist are listed here. (This can also be a good way to get an idea of what Shortlist is doing under the hood)
Note: In these docs we'll be using the default action word trigger of 'action'. This can be changed per-install, so your install may differ. For safety use the native actionUrl()
method to build up your action urls rather than hardcoding.
GET or POST?
All actions can be triggered by both GET requests (ie. via a link like '/action/..') or via POST requests (ie. a form post submission). Shortlist accepts both methods throughout except for certain methods which are limited to POST only actions for security. Currently only list/clearAll and list/deleteAll are limited to POST only actions.
Building Action Urls for GET requests
We'll use the native actionUrl()
function to build all our action urls. Usage is like so :
<a href="{{ actionUrl('pluginClass/pluginMethod', { optionalParams .. }) }}">Some Action</a>
Setting Action urls for POST requests
If you want to trigger actions via a post request simply add a hidden action input with the path to the method in the value. Like so :
<input type="hidden" name="action" value="pluginClass/pluginMethod"/>
All additional values would be passed as seperate inputs.
Item Actions
All item based actions are on a base route of shortlist/item
.
- Add an Item
shortlist/item/add
available as{{ item.addActionUrl }}
Parametersid
*required, the id for the element to addlistId
optional, the listId to add the item to, if not passed, will use the default listreturn
optional, the return path for the action. Will default to current url if not specified>
- Remove an Item
shortlist/item/remove
available as{{ item.removeActionUrl }}
Parametersid
*required, the id for the element to removelistId
optional, the listId to remove the item from, if not passed, will use the default listreturn
optional, the return path for the action. Will default to current url if not specified>
- Toggle an Item
shortlist/item/toggle
available as{{ item.toggleActionUrl }}
Parametersid
*required, the id for the element to togglelistId
optional, the listId to toggle the item in, if not passed, will use the default listreturn
optional, the return path for the action. Will default to current url if not specified>
List Actions
All list based actions are on a base route of shortlist/list
.
- Create a new List
shortlist/list/create
available as{{ shortlist.newList }}
Parameterstitle
optional, the name of the new list, if not passed, will use the default as defined in the settingsreturn
optional, the return path for the action. Will default to current url if not specified>
- Delete a new List
shortlist/list/delete
available as{{ list.delete }}
ParameterslistId
*required, the id of the list to deletereturn
optional, the return path for the action. Will default to current url if not specified>
- Clear a list
shortlist/list/clear
available as{{ list.clear }}
ParameterslistId
*required, the id of the list to clearreturn
optional, the return path for the action. Will default to current url if not specified>
- Make Default
shortlist/list/makeDefault
available as{{ list.makeDefault }}
ParameterslistId
*required, the id of the list to make defaultreturn
optional, the return path for the action. Will default to current url if not specified>
- Clear All *requires POST request
shortlist/list/clearAll
Parametersreturn
optional, the return path for the action. Will default to current url if not specified>
- Delete All *requires POST request
shortlist/list/deleteAll
Parametersreturn
optional, the return path for the action. Will default to current url if not specified>