{"id":22337308,"url":"https://github.com/handmadeweb/frosty","last_synced_at":"2025-03-26T08:23:02.154Z","repository":{"id":56983699,"uuid":"392863067","full_name":"HandmadeWeb/frosty","owner":"HandmadeWeb","description":"Frosty provides easy access to fetch Ajax content in Statamic.","archived":false,"fork":false,"pushed_at":"2023-07-10T11:51:27.000Z","size":151,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-31T09:44:34.471Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HandmadeWeb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-05T00:59:40.000Z","updated_at":"2022-06-07T09:55:08.000Z","dependencies_parsed_at":"2022-08-21T11:20:47.264Z","dependency_job_id":null,"html_url":"https://github.com/HandmadeWeb/frosty","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HandmadeWeb%2Ffrosty","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HandmadeWeb%2Ffrosty/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HandmadeWeb%2Ffrosty/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HandmadeWeb%2Ffrosty/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HandmadeWeb","download_url":"https://codeload.github.com/HandmadeWeb/frosty/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245615817,"owners_count":20644533,"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-12-04T06:09:30.751Z","updated_at":"2025-03-26T08:23:02.121Z","avatar_url":"https://github.com/HandmadeWeb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![MIT Licensed](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE.md)\n\nFrosty provides easy access to fetch Ajax content in Statamic.\n\n## Requirements\n\n* PHP 8.0 or higher\n* Statamic 3.1 or higher\n\n## Installation\n\nYou can install the package via composer:\n\n```shell\ncomposer require handmadeweb/frosty\n```\n\n### Copy the package config to your local config with the publish command:\n\n```shell\nphp artisan vendor:publish --tag=\"config\" --provider=\"HandmadeWeb\\Frosty\\ServiceProvider\"\n```\n\n### Prepare for Usage\n#### Native Method\nIf you aren't using Alpine Js in your application then you'll need to load [handmadeweb/datafetcher.js](https://github.com/HandmadeWeb/datafetcher.js) in your footer, you can either do this manually, or via the provided helpers for Alpine: `{{ frosty:scripts }}`, Blade: `@frostyScripts` or PHP: `\\HandmadeWeb\\Frosty\\Frosty::scripts();`\n\nThis method uses the `native.blade.php` view, you are free to override it in `resources/vendor/frosty/`, you will have access to the `content`, `endpoint` and `mode` variables.\n\n#### Alpine.Js Method\n\nIf you are using Alpine.Js in your application then you may update your Frosty configuration to use Alpine.\n```php\n/*\n* Mode\n*\n* Which mode to use?\n*\n* native: uses https://github.com/handmadeweb/datafetcher.js\n* - If you aren't using Alpine Js in your application then you'll need to load handmadeweb/datafetcher.js in your footer.\n* - You can either do this manually, or via the provided helpers for Alpine: `{{ frosty:scripts }}`\n* - Blade: `@frostyScripts` or PHP: `\\HandmadeWeb\\Frosty\\Frosty::scripts();`\n*\n* alpine: uses Alpine.Js, be sure to load it.\n*/\n'mode' =\u003e 'alpine',\n```\n\nThis method uses the `alpine.blade.php` view, you are free to override it in `resources/vendor/frosty/`, you will have access to the `content`, `endpoint` and `mode` variables.\n\n#### Custom Method\n\nYou are free to use a custom method, you may do so by defining a new view template for Frosty to use under `resources/vendor/frosty`, the filenames `alpine`, `native` and `not-found` are considered to be reserved, although you may override them if you wish.\n\nOnce you have created a new view for your mode, you will have access to the `content`, `endpoint` and `mode` variables, you may then use this to provide the content or endpoint to your custom method.\n\nThen it is just a matter of updating the mode to use the name of your new method/view.\n\nLets say we created a file called `myCustomVueMode.blade.php` which might contain something like,\n```blade\n\u003cvue-fetcher endpoint=\"{{ $endpoint }}\" initial-content=\"{!! $content !!}\" /\u003e\n```\n\nYou would then update your mode to:\n```php\n'mode' =\u003e 'myCustomVueMode',\n```\n\nIn the event that your custom method/mode doesn't have a corresponding view file, then Frosty will insert some HTML comments in the location of where it would have rendered your method.\n\n```html\n\u003c!-- Frosty could not be rendered, Mode not found --\u003e\n\n\u003c!-- If the page is being viewed by a Super Administrator, then the below will also be inserted as a comment. --\u003e\n\u003c!-- Mode: {{ $mode }} --\u003e\n\u003c!-- Endpoint: {{ $endpoint }} --\u003e\n```\n\n## Antlers Usage\nUsing Frosty in `Antlers` can be done by using the `frosty` tag or if you are using an `.antlers.php` template file by using the `class` (see class instructions)\n\nYou can use the tag as either `frosty:fetch` or just `frosty`, I like `frosty:fetch` a little more though as it describes what it is doing.\n\n### Pulling in content from a url.\nThe url can be anywhere.\n```antlers\n{{ frosty:fetch url=\"/ajax/signup-form\" }}\n```\nOr\n```antlers\n{{ frosty:fetch endpoint=\"/ajax/signup-form\" }}\n```\n\n### Pulling in content from a route.\nRoutes must be a GET route and cannot currently accept parameters.\n```antlers\n{{ frosty:fetch route=\"ajax.signup-form\" }}\n```\n\nPlease note that the above three examples cannot be combined into a single tag call.\n```antlers\n{{ frosty:fetch endpoint=\"/ajax/signup-form\" url=\"/ajax/signup-form\" route=\"ajax.signup-form\" }}\n{{ frosty:fetch route=\"ajax.signup-form\" endpoint=\"/ajax/signup-form\" url=\"/ajax/signup-form\" }}\n```\nThe first found parameter will be used, parameters are checked in the order: endpoint, url, route.\n\n### Using initial content then pulling new content.\nThis works with both the route and url options.\n```antlers\n{{ frosty:fetch route=\"ajax.news\" }}\n    \u003cp\u003eFinding something juicy!\u003c/p\u003e\n{{ /frosty:fetch }}\n```\n\n### Using a different mode/view.\nYou are free to use any other mode/view that might be available for Frosty to use, separately to whatever you might have set as the config default.\nYou can do this by passing the mode parameter, which will relate to the name of a view file located in `resources/vendor/frosty/`\n```antlers\n{{ frosty:fetch route=\"ajax.news\" mode=\"myCustomVueMode\" }}\n    \u003cp\u003eFinding something juicy!\u003c/p\u003e\n{{ /frosty:fetch }}\n```\n\n## Blade Usage\nUsing Frosty in `Blade` can be done by using the `frosty` blade directive or by using the `class` (see class instructions)\nThe blade directive currently doesn't accept providing content or context, If you need to use that functionality the you'll need to use the class chaining method.\n\n```blade\n@frosty(string $endpoint = null)\n```\n\nYou can also use named arguments in PHP 8+ to specify particular parameters.\n```blade\n@frosty(endpoint: '/ajax/sponsors')\n```\n\n### Pulling in content from a url.\n\n```blade\n@frosty('/ajax/sponsors')\n```\n\n### Pulling in content from a route.\n```blade\n@frosty(route('ajax.sponsors', 'featured'))\n```\n\n### Using a different mode/view.\nYou are free to use any other mode/view that might be available for Frosty to use, separately to whatever you might have set as the config default.\nYou can do this by passing the mode parameter, which will relate to the name of a view file located in `resources/vendor/frosty/`\n```blade\n@frosty(route('ajax.sponsors', 'featured'), 'myCustomVueMode')\n```\n\n## Class Usage\nNew up the class.\n```php\nnew Frosty(string $endpoint = null)\n```\nOr use the make method.\n```php\nFrosty::make(string $endpoint = null)\n```\nYou can also use named arguments in PHP 8+ to specify particular parameters.\n```php\n$frosty = Frosty::make(endpoint: '/ajax/random-quote');\n```\n\nYou are free to use any other mode/view that might be available for Frosty to use, separately to whatever you might have set as the config default.\nYou can do this by passing the mode (or second) parameter, which will relate to the name of a view file located in `resources/vendor/frosty/`\n```php\n$frosty = Frosty::make('/ajax/random-quote', 'myCustomVueMode');\n// You are free to use the named argument style of mode: 'myCustomVueMode'\n```\n\nAditional methods can be chained to add content and context, or to set the endpoint.\n```php\n$frosty = Frosty::make();\n$frosty-\u003ewithContent($content); // string\n$frosty-\u003ewithContext($context); // \\Statamic\\Tags\\Context or \\Illuminate\\Support\\Collection (Used to provide Cascaded variables to the content)\n$frosty-\u003ewithEndpoint($endpoint); // string\n```\n\nWhen using the tag, you'll specify if the endpoint is a url or a route, however when using the class directly, the endpoint is assumed to be a url string, if you wish to pass a route to it instead, then you are welcome to do that.\n\nUnlike when using the Frosty tag, the Frosty class can directly accept parameters on the route below.\n```php\nFrosty::make(route('ajax.cart', $user-\u003eid())\n// or\nFrosty::make()-\u003ewithEndpoint(route('ajax.cart', $user-\u003eid())\n```\n\nWhen you are ready to output the content, then you may call the render method.\n```php\nFrosty::make()\n    -\u003ewithContent($content) // Optional\n    -\u003ewithContext($context) // Optional\n    -\u003ewithEndpoint($endpoint) // Optional (could be set on class or make), If no endpoint has been set, then we won't bother trying to render.\n    -\u003erender();\n```\n\n## Changelog\n\nPlease see [CHANGELOG](https://statamic.com/addons/handmadeweb/frosty/release-notes) for more information what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/handmadeweb/frosty/blob/main/CONTRIBUTING.md) for details.\n\n## Credits\n\n- [Handmade Web \u0026 Design](https://github.com/handmadeweb)\n- [Michael Rook](https://github.com/michaelr0)\n- [All Contributors](https://github.com/handmadeweb/frosty/graphs/contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](https://github.com/handmadeweb/frosty/blob/main/LICENSE) for more information.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhandmadeweb%2Ffrosty","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhandmadeweb%2Ffrosty","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhandmadeweb%2Ffrosty/lists"}