Echo ViewKit provides a comprehensive server side template rendering for Echo.
Templating engine.
Echo ViewKit has a built-in templating engine that is forked from Pongo2. It provides a Django-like syntax. It is easy to use in your Echo application.
Learn more{# if statement #}
{% if errorMessage %}
<div>{{ errorMessage }}</div>
{% endif %}
{# for loop #}
{% for user in users %}
<div>{{ user.Name }}</div>
{% endfor %}
// Go code that calls the above template.
type IndexProps struct {
ErrorMessage string `pongo2:"errorMessage"`
Users []*User `pongo2:"users"`
// ...
}
func IndexHandler(c echo.Context) error {
users := ...
return c.Render(http.StatusOK, "index", &IndexProps{
ErrorMessage: "Something went wrong.",
Users users,
})
}
Component-based.
You can use component-based architecture like Laravel Blade. It enhances code organization and maintainability. You can implement your components with Go code and Pongo2 templates.
Learn more{# render an alert message... #}
<x-alert type="success" :message="message"/>
{# slots are supported... #}
<x-alert>
<x-slot name="title">Custom title</x-slot>
<x-slot name="message">This is a success message.</x-slot>
</x-alert>
{# scoped slots are also supported... #}
<x-counter slot-data="{count}" >
<div>{{ count }}</div>
</x-counter>
Vite integration.
You can use Vite to build your front-end assets and integrate them with Echo ViewKit.
Learn moreAbsolutely! This website is built with Echo ViewKit. You can see the entire source code.
View the source code