Skip to content

How to Dynamically add a class to a item? #938

Answered by a-h
Tesohh asked this question in Q&A
Discussion options

You must be logged in to vote

Something like this should work:

type Course struct {
	Name  string
	Color string
}

templ button(text string, course Course) {
	<button class={ "coursecard", fmt.Sprintf("card-color-%s", course.Color) }>{ text }</button>
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Tesohh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants