An open API service indexing awesome lists of open source software.

https://github.com/statamic/rucksack


https://github.com/statamic/rucksack

Last synced: 3 months ago
JSON representation

Awesome Lists containing this project

README

        

# Rucksack ![Statamic 2.0](https://img.shields.io/badge/statamic-2.0-blue.svg?style=flat-square)
> 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 rucksack

Outputs:
Add to rucksack
```

## Removing an item from your rucksack
```
Remove

Outputs:
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.