attr

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

README

attr.FuncMap Template Functions

The attr.FuncMap provides several utility functions for working with HTML attributes in Go templates. Below is a description of each function and examples of how they can be used in templates.

attr_class

Combines multiple class names into a single string, filtering out any empty strings.

Usage:

<div class="{{ attr_class "card" (when .IsLarge "card-lg") (unless .IsVisible "hidden") }}">Content</div>

attr_safe

Marks a string as safe for HTML attribute output.

Usage:

<input type="text" value="{{ attr_safe .Value }}">

attr_selected

Returns "selected" if the current value matches the value, otherwise returns an empty string.

Usage:

<option value="option1" {{ attr_selected .CurrentValue "option1" }}>Option 1</option>

attr_checked

Returns "checked" if the current value matches the value, otherwise returns an empty string.

Usage:

<input type="checkbox" {{ attr_checked .IsChecked "true" }}>

attr_disabled

Returns "disabled" if the current value matches the value, otherwise returns an empty string.

Usage:

<button {{ attr_disabled .IsDisabled "true" }}>Submit</button>

attr_readonly

Returns "readonly" if the current value matches the value, otherwise returns an empty string.

Usage:

<input type="text" {{ attr_readonly .IsReadonly "true" }}>

These functions help ensure that HTML attributes are correctly and safely rendered in templates, improving both security and readability.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FuncMap

func FuncMap() template.FuncMap

FuncMap returns a template.FuncMap for HTML templates

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL