{"id":18369976,"url":"https://github.com/statamic/rucksack","last_synced_at":"2025-04-10T19:44:47.869Z","repository":{"id":146133542,"uuid":"60272625","full_name":"statamic/rucksack","owner":"statamic","description":null,"archived":false,"fork":false,"pushed_at":"2016-06-06T20:51:45.000Z","size":6,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-15T20:57:08.257Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/statamic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-02T14:51:31.000Z","updated_at":"2024-01-03T03:38:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"9b64f3b0-8b70-4e35-a390-0483eed063d1","html_url":"https://github.com/statamic/rucksack","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statamic%2Frucksack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statamic%2Frucksack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statamic%2Frucksack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/statamic%2Frucksack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/statamic","download_url":"https://codeload.github.com/statamic/rucksack/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248281425,"owners_count":21077423,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T23:34:52.047Z","updated_at":"2025-04-10T19:44:47.838Z","avatar_url":"https://github.com/statamic.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rucksack ![Statamic 2.0](https://img.shields.io/badge/statamic-2.0-blue.svg?style=flat-square)\n\u003e Allow your users to add content and assets to their session. Like a cart for content!\n\n## Usage example\nLet's say you have a portfolio of projects which contains images. You want to allow your\nusers to pick their favorite images. With Rucksack, you can let your users add the\nimage assets to their \"rucksack\" (or \"cart\").\n\n## Add to rucksack\n```\n\u003ca href=\"\n{{ rucksack:add_url\n   id=\"123\"                  # The ID of the content you're adding. Leave this off to get id from context.\n   extra:foo=\"bar\"           # Any extra data you want to be made available as single tags.\n   extra:project_id=\"456\"    # If it ends with _id, it will be converted to the content.\n}}\n\"\u003eAdd to rucksack\u003c/a\u003e\n\nOutputs:\n\u003ca href=\"/!/Rucksack/add/123?foo=bar\u0026project_id=456\"\u003eAdd to rucksack\u003c/a\u003e\n```\n\n## Removing an item from your rucksack\n```\n\u003ca href=\"{{ rucksack:remove_url id=\"123\" }}\"\u003eRemove\u003c/a\u003e\n\nOutputs:\n\u003ca href=\"/!/Rucksack/remove/123\"\u003eRemove\u003c/a\u003e\n```\n\n## Checking if an item is in your rucksack\n```\n{{ if {rucksack:has id=\"123\"} }}\n    You have this!\n{{ else }}\n    You don't have this!\n{{ /if }}\n```\n\n## Outputting rucksack contents\n```\n{{ rucksack:contents as=\"items\" }}\n\n    {{ if no_results }}\n\n        Rucksack is empty!\n\n    {{ else }}\n\n        \u003cdiv class=\"rucksack-items\"\u003e\n\n            {{ items }}\n                \u003c!-- Variables from the item you added are available --\u003e\n                {{ title }}, {{ url }}, etc\n\n                \u003c!-- \"Extra\" variables you specified when adding to the rucksack are available --\u003e\n                {{ foo }}\n\n                \u003c!-- \"Extra\" variables that were suffixed by _id are converted to their content,\n                     and available in an array --\u003e\n                {{ project }}\n                    {{ title }}, {{ url }}, etc\n                {{ /project }}\n\n                \u003c!-- Of course, they're available using a colon syntax --\u003e\n                {{ project:title }}, {{ project:url }}, etc\n\n                \u003c!-- Remove items like this. The ID will be resolved from the context. --\u003e\n                \u003ca href=\"{{ rucksack:remove_url }}\"\u003eRemove\u003c/a\u003e\n            {{ /items }}\n\n        \u003c/div\u003e\n\n    {{ /if }}\n{{ /rucksack:contents }}\n```\n\n## External Access\n\nWhen you add something to your rucksack, since it's managed in session, it's only available to you.\nTo facilitate sharing of a rucksack's contents, you may generate a hash and reference that\nwhen outputting contents.\n\n```\n/wishlist?hash={{ rucksack:external_hash }}\n```\n\nThis will save the rucksack's contents to cache and outputs a corresponding hash. Something like:\n\n```\n/wishlist?hash=f8d9aoh4389fdsf\n```\n\nThen in your `{{ rucksack:contents }}` tag, passing along the hash will output the contents for _that_ rucksack:\n\n```\n{{ rucksack:contents hash=\"{get:hash}\" }}\n    ...\n{{ /rucksack:contents }}\n```\n\nNote that the hashed value will only correspond to the contents for when it was generated. Any updates to the\nrucksack will not be reflected unless a new hash is generated.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatamic%2Frucksack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstatamic%2Frucksack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstatamic%2Frucksack/lists"}