Adds web components to the existing pongo2 template engine.
Now you can make components similar to how you would in popular JS frameworks.
Install via go get -u github.com/leandergangso/pongo2-components
Import and initialize the package as seen bellow.
package main
import (
"github.com/flosch/pongo2"
"github.com/leandergangso/pongo2-components"
)
func init() {
err := pongo2components.Init()
if err != nil {
panic(err)
}
}
func main() {
// ...
}
Note: you should init pongo2components
before any calls to pongo2
.
A basic button component.
- Registering and setup button component.
// components/button.go
package components
import (
"github.com/leandergangso/pongo2-components"
)
func init() {
button := pongo2components.Component{
Name: "button",
FilePath: "components/button.html",
Props: []pongo2components.Prop{"value", "type"}
}
pongo2components.Register(button)
}
- Create html component with available props.
<!-- components/button.html -->
<button class="{{type}}">{{value}}</button>
- Use button component.
<!-- views/login.html -->
{% component 'button' value="Login" type="primary" %}
See /example directory for more examples.