using Spry; /** * ComponentsTemplateSyntaxPage - Documentation for Spry template syntax * * This page covers all the special HTML attributes and elements used in * Spry component templates. */ public class ComponentsTemplateSyntaxPage : PageComponent { public const string ROUTE = "/components/template-syntax"; public override string markup { get { return """
Spry extends HTML with special attributes that enable reactive behavior, component composition, and dynamic content. This page covers all the template syntax available in Spry components.
sid - Spry ID
The sid attribute assigns a unique identifier to an element within
a component. Use it to select and manipulate elements in your Vala code.
spry-action - HTMX Action Binding
The spry-action attribute binds an element to trigger a component action
when interacted with. The action is sent to the server via HTMX.
See the Actions page for more details.
spry-target - Scoped Targeting
The spry-target attribute specifies which element should be replaced
when an action completes. It targets elements by their sid within the
same component.
spry-global - Out-of-Band Swaps
The spry-global attribute marks an element for out-of-band updates.
When included in a response, HTMX will swap this element anywhere on the page
that has a matching id.
*-expr - Expression Attributes
Expression attributes dynamically set HTML attributes based on component properties.
Use content-expr for text content, class-*-expr for
conditional classes, and any-attr-expr for any other attribute.
spry-if / spry-else-if / spry-else - ConditionalsUse these attributes for conditional rendering. Only elements with truthy conditions will be included in the output.
spry-per-* - Loop Rendering
Use spry-per-{varname}="expression" to iterate over collections.
The variable name becomes available in nested expressions.
<spry-outlet> - Child Component Outlets
Outlets are placeholders where child components can be inserted dynamically.
Use set_outlet_children() to populate outlets.
See the Outlets page for more details.
<spry-component> - Declarative Child Components
Use <spry-component> to declare child components directly in
your template. Access them with get_component_child<T>().
<spry-context> - Context Property Preservation
The <spry-context> tag marks a property to be preserved across
action requests. When a component action is triggered, properties marked with this
tag are encrypted and included in the action URL, then restored when the action
is handled.
<spry-context property="name"/> are trackedCryptographyProviderhandle_action()The encrypted context can be captured and replayed by malicious actors. While the data cannot be tampered with (it's cryptographically signed), an attacker could capture a valid request and replay it later.
Example attack: If context contains admin privileges, an attacker could capture a request from an admin session and replay it to gain unauthorized access.
spry-res - Static Resources
Use spry-res to reference Spry's built-in static resources.
This resolves to /_spry/res/{resource-name} automatically.