template - Plugin operators
This page lists all operators available in the template sub-package of ro.
Help improve this documentation
This documentation is still new and evolving. If you spot any mistakes, unclear explanations, or missing details, please open an issue.
Your feedback helps us improve!
Installโ
First, import the sub-package in your project:
go get -u github.com/samber/ro/plugins/template
TextTemplateโ
Applies text template to values.
import ("github.com/samber/ro"rotemplate "github.com/samber/ro/plugins/template")type User struct {Name stringAge int}obs := ro.Pipe[User, string](ro.Just(User{Name: "Alice", Age: 30}),rotemplate.TextTemplate[User]("Hello {{.Name}}, you are {{.Age}} years old"),)sub := obs.Subscribe(ro.PrintObserver[string]())defer sub.Unsubscribe()// Next: Hello Alice, you are 30 years old// CompletedSimilar:Prototype:func TextTemplate[T any](template string)HTMLTemplateโ
Applies HTML template to values.
import ("github.com/samber/ro"rotemplate "github.com/samber/ro/plugins/template")type Item struct {Name stringPrice float64}obs := ro.Pipe[Item, string](ro.Just(Item{Name: "Apple", Price: 1.99}),rotemplate.HTMLTemplate[Item]("<h1>{{.Name}}</h1><p>Price: ${{.Price}}</p>"),)sub := obs.Subscribe(ro.PrintObserver[string]())defer sub.Unsubscribe()// Next: <h1>Apple</h1><p>Price: $1.99</p>// CompletedSimilar:Prototype:func HTMLTemplate[T any](template string)