Attributes

Six attribute forms, all inherited from the baseline:

templ attrs(href string, hidden bool, extra ghtmx.Attributes) {
	<a
		id="constant"
		href={ ghtmx.URL(href) }
		disabled?={ hidden }
		download
		if hidden {
			aria-hidden="true"
		}
		{ "data-" + "computed" }={ "dynamic key" }
		{ extra... }
	>link</a>
}
  • constant (ConstantAttribute) and boolean-constant (BoolConstantAttribute),
  • expression value (ExpressionAttribute) and boolean-expression (BoolExpressionAttribute, the ?= form),
  • conditional blocks inside the tag (ConditionalAttribute),
  • spreads (SpreadAttributes, { attrs... }).

Attribute names may themselves be dynamic (AttributeKey, ConstantAttributeKey, ExpressionAttributeKey), comments may sit between attributes (AttributeComment), class values compose from strings and css templates, and style values accept strings (breakout-escaped) or maps (property-value sanitized) โ€” see conformance for the escaping contract. The Attribute interface is the AST umbrella for all of these.

Verified by: internal/generator/test-element-attributes, internal/generator/test-complex-attributes, internal/generator/test-attribute-escaping, internal/generator/test-constant-attribute-escaping, internal/generator/test-attribute-comments, internal/generator/test-attribute-errors, internal/generator/test-spread-attributes, internal/generator/test-class-whitespace, internal/generator/test-style-attribute, internal/generator/test-form-action, internal/generator/test-a-href.