{"id":15307182,"url":"https://github.com/putyourlightson/craft-htmx","last_synced_at":"2025-06-12T06:41:05.154Z","repository":{"id":57046009,"uuid":"266376138","full_name":"putyourlightson/craft-htmx","owner":"putyourlightson","description":"Provides helpers for integrating Htmx with Craft CMS.","archived":false,"fork":false,"pushed_at":"2023-06-06T19:33:47.000Z","size":60,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"v1","last_synced_at":"2024-10-02T08:09:30.841Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/putyourlightson.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-05-23T16:30:32.000Z","updated_at":"2024-10-01T14:35:07.000Z","dependencies_parsed_at":"2022-08-24T05:00:19.417Z","dependency_job_id":null,"html_url":"https://github.com/putyourlightson/craft-htmx","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/putyourlightson%2Fcraft-htmx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/putyourlightson%2Fcraft-htmx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/putyourlightson%2Fcraft-htmx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/putyourlightson%2Fcraft-htmx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/putyourlightson","download_url":"https://codeload.github.com/putyourlightson/craft-htmx/tar.gz/refs/heads/v1","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228242555,"owners_count":17890481,"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-10-01T08:09:21.857Z","updated_at":"2024-12-05T06:11:10.453Z","avatar_url":"https://github.com/putyourlightson.png","language":"PHP","funding_links":[],"categories":["Tools"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg width=\"130\" src=\"https://raw.githubusercontent.com/putyourlightson/craft-htmx/v1/src/icon.svg\"\u003e\u003c/p\u003e\n\n# Htmx Plugin for Craft CMS 3\n\n\u003e This plugin is no longer maintained and has been replaced by [Sprig](https://putyourlightson.com/plugins/sprig).\n\nProvides components and helpers for using [Htmx](https://htmx.org/) with [Craft CMS 3](https://craftcms.com/).\n\nThe plugin will automatically route any action requests made from Htmx through the `htmx/route` controller to ensure that the result is always in the format `text/html` and that no redirects take place.\n\n## Variables\n\nThe `craft.htmx` variable (and the shorthand version `hx`) is available in your twig templates. It provides components as well as values passed in through the [Htmx request headers](https://htmx.org/docs/#request-headers).\n\n### `craft.htmx.component(template, options = {})`\nRenders a reactive component using the provided template.\n\n```twig\n{{ hx.component('path/to/template', { \n    params: {\n        entryId: entry.id,\n        title: entry.title,\n    },\n}) }}\n```\n\nThe `params` automatically become available as twig variables in the component:\n\n```twig\nEntry ID: {{ entryId }}\n\n{# Add `hx-get` to make the input field reactive #}\n\u003cinput hx-get type=\"text\" name=\"title\" value=\"{{ title }}\"\u003e\n{{ title|length }} characters of max 255\n\n{# Any `hx-` attributes can be used #}\n\u003cbutton hx-get hx-confirm=\"Are you sure?\"\u003eRefresh\u003c/button\u003e\n```\n\n### `craft.htmx.get(tag, options = {})`\nRenders a `get` component using the provided tag and options.\n\n```twig\n{# Minimal example #}\n{{ hx.get('div', { \n    content: 'Like', \n}) }}\n\n{# Example with all possible options #}\n{{ hx.get('button', {\n    url: '/like',\n    content: 'Like',\n    params: {\n        entryId: 1,\n    },\n    hx: {\n        trigger: 'click',\n    },\n    attributes: {\n        class: 'btn',\n    }\n}) }}\n```\n\nWhich will be output as:\n\n```twig\n{# Minimal example #}\n\u003cdiv hx-get=\"\"\u003eLike\u003c/div\u003e\n\n{# Example with all possible options #}\n\u003cbutton hx-get=\"/like?entryId=1\" hx-trigger=\"click\" class=\"btn\"\u003eLike\u003c/button\u003e\n```\n\n### `craft.htmx.post(tag, options = {})`\nRenders a `post` component using the provided tag and options. A CSRF token will automatically be added _if_ CSRF validation is enabled. \n\n```twig\n{# Minimal example #}\n{{ hx.post('form', {\n    content: '\u003cinput type=\"submit\" value=\"Like\"\u003e',\n}) }}\n\n{# Example with all possible options #}\n{{ hx.post('form', {\n    url: '/like',\n    content: '\u003cinput type=\"submit\" value=\"Like\"\u003e',\n    params: {\n        entryId: 1,\n    },\n    hx: {\n        confirm: 'Are you sure?',\n    },\n    attributes: {\n        class: 'form',\n    }\n}) }}\n```\n\nWhich will be output as:\n\n```twig\n{# Minimal example #}\n\u003cform hx-post=\"\"\u003e\n  \u003cinput type=\"hidden\" name=\"CRAFT_CSRF_TOKEN\" value=\"UIfhSl2qN0084dgj6NJdHcCTnL5xFPJ...\"\u003e\n  \u003cinput type=\"submit\" value=\"Like\"\u003e\n\u003c/form\u003e\n\n{# Example with all possible options #}\n\u003cform hx-post=\"/like\" hx-confirm=\"Are you sure?\" class=\"form\"\u003e\n  \u003cinput type=\"hidden\" name=\"CRAFT_CSRF_TOKEN\" value=\"UIfhSl2qN0084dgj6NJdHcCTnL5xFPJ...\"\u003e\n  \u003cinput type=\"hidden\" name=\"entryId\" value=\"1\"\u003e\n  \u003cinput type=\"submit\" value=\"Like\"\u003e\n\u003c/form\u003e\n```\n\n### `craft.htmx.script(attributes = {})`\nReturns a script tag to include the latest version of Htmx from unpkg.com.\n\n```twig\n\u003cscript src=\"https://unpkg.com/htmx.org\"\u003e\u003c/script\u003e\n```\n\n### `craft.htmx.request`\nReturns `true` if this is a Htmx request, otherwise `false`.\n\n### `craft.htmx.trigger.id`\nReturns the ID of the element that triggered the request.\n\n### `craft.htmx.trigger.name`\nReturns the name of the element that triggered the request.\n\n### `craft.htmx.target.id`\nReturns the ID of the target element.\n\n### `craft.htmx.url`\nReturns the URL of the browser.\n\n### `craft.htmx.prompt`\nReturns the value entered by the user when prompted via `hx-prompt`.\n\n### `craft.htmx.eventTarget.id`\nReturns the ID of the original target of the event that triggered the request.\n\n### `craft.htmx.element.id`\nReturns the ID of the current active element.\n\n### `craft.htmx.element.name`\nReturns the name of the current active element.\n\n### `craft.htmx.element.value`\nReturns the value of the current active element.\n\n## Requirements\n\nCraft CMS 3.0.0 or later.\n\n## Installation\n\nInstall the plugin using composer.\n\n```\ncomposer require putyourlightson/craft-htmx:^0.1.0\n```\n\n## License\n\nThis plugin is licensed for free under the MIT License.\n\n\u003csmall\u003eCreated by [PutYourLightsOn](https://putyourlightson.com/).\u003c/small\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fputyourlightson%2Fcraft-htmx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fputyourlightson%2Fcraft-htmx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fputyourlightson%2Fcraft-htmx/lists"}