### Install htmx.org via npm Source: https://putyourlightson.com/plugins/sprig/index This command shows how to install the htmx.org package using npm, allowing developers to manage htmx as a project dependency. This approach requires manual updates to keep htmx in sync with Sprig's requirements. ```Bash npm install htmx.org ``` -------------------------------- ### Install Sprig Plugin via Composer Source: https://putyourlightson.com/plugins/sprig/index This command installs the Sprig plugin for Craft CMS using Composer, the PHP dependency manager. It's the recommended way to add the plugin to your Craft project. ```Shell composer require putyourlightson/craft-sprig ``` -------------------------------- ### s-on:* Attribute Usage Source: https://putyourlightson.com/plugins/sprig/index Demonstrates how to use the s-on:* attribute to respond to events directly on an HTML element, similar to htmx's hx-on. The example shows toggling a CSS class on click. ```HTML
{{ entry.title }}
{% endfor %} {% if entries %}{{ error|first }}
{% endfor %} {% endif %} {% endif %} ``` -------------------------------- ### s-listen Attribute for Component Refresh Triggering Source: https://putyourlightson.com/plugins/sprig/index The `s-listen` attribute allows an element to refresh automatically when one or more specified components are refreshed. Components are identified by CSS selectors. This attribute is commonly used with the `sprig` function's third parameter to create reactive component interactions. ```Twig {{ sprig('_components/products', {}, {'id': 'products'}) }} {# This component is refreshed each time the `#product` component is refreshed. #} {{ sprig('_components/cart', {}, {'s-listen': '#products'}) }} {# Equivalent to: #} {{ sprig('_components/cart', {}, {'s-trigger': 'htmx:afterOnLoad from:#products'}) }} ``` -------------------------------- ### Force Browser Page Refresh Source: https://putyourlightson.com/plugins/sprig/index Instructs the browser to perform a full refresh of the current page. This can be used to ensure the latest content is displayed. ```Twig {% do sprig.refresh() %} ``` -------------------------------- ### s-cache Attribute for Local Caching Source: https://putyourlightson.com/plugins/sprig/index The `s-cache` attribute allows developers to control local browser caching for requests. It can specify a duration in seconds for which a request's response should be cached. If no duration is provided, it defaults to 300 seconds. ```HTML