https://github.com/statamic/rucksack
https://github.com/statamic/rucksack
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/statamic/rucksack
- Owner: statamic
- Created: 2016-06-02T14:51:31.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-06-06T20:51:45.000Z (about 9 years ago)
- Last Synced: 2025-02-15T20:57:08.257Z (4 months ago)
- Language: PHP
- Size: 5.86 KB
- Stars: 1
- Watchers: 5
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Rucksack 
> Allow your users to add content and assets to their session. Like a cart for content!## Usage example
Let's say you have a portfolio of projects which contains images. You want to allow your
users to pick their favorite images. With Rucksack, you can let your users add the
image assets to their "rucksack" (or "cart").## Add to rucksack
```
Add to rucksackOutputs:
Add to rucksack
```## Removing an item from your rucksack
```
RemoveOutputs:
Remove
```## Checking if an item is in your rucksack
```
{{ if {rucksack:has id="123"} }}
You have this!
{{ else }}
You don't have this!
{{ /if }}
```## Outputting rucksack contents
```
{{ rucksack:contents as="items" }}{{ if no_results }}
Rucksack is empty!
{{ else }}
{{ items }}
{{ title }}, {{ url }}, etc
{{ foo }}
{{ project }}
{{ title }}, {{ url }}, etc
{{ /project }}
{{ project:title }}, {{ project:url }}, etc
Remove
{{ /items }}
{{ /if }}
{{ /rucksack:contents }}
```## External Access
When you add something to your rucksack, since it's managed in session, it's only available to you.
To facilitate sharing of a rucksack's contents, you may generate a hash and reference that
when outputting contents.```
/wishlist?hash={{ rucksack:external_hash }}
```This will save the rucksack's contents to cache and outputs a corresponding hash. Something like:
```
/wishlist?hash=f8d9aoh4389fdsf
```Then in your `{{ rucksack:contents }}` tag, passing along the hash will output the contents for _that_ rucksack:
```
{{ rucksack:contents hash="{get:hash}" }}
...
{{ /rucksack:contents }}
```Note that the hashed value will only correspond to the contents for when it was generated. Any updates to the
rucksack will not be reflected unless a new hash is generated.