pongo2echo

package module
v0.0.0-...-1f90ccb Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2021 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Pongo2echo

Package pongo2echo is a template renderer that can be used with the minimalist Go web framework https://github.com/labstack/echo it uses the Pongo2 template library https://github.com/flosch/pongo2

pongo2 is a Django-syntax like templating-language (official website).

Installation

go get "github.com/stnc/pongo2echo"

Here is Compatible with pongo version 4

Pongo4echo - pongo2 echo framework stability renderer / Compatible with pongo version 4

please don't forget to give stars :)

Requirements

Requires Echo 4+ or higher and Pongo2.

Usage

Real Example [echo+pongo+gorm+pagination]

https://github.com/stnc/golang-echo-realworld-example-web-app

Screen

Basic Example

package main

import (
	"net/http"

	"github.com/flosch/pongo2"
	"github.com/labstack/echo/v4"
	"github.com/stnc/pongo2echo"
)

var (
	data         = pongo2.Context{}
	mainRenderer = pongo2echo.Renderer{Debug: true} // use any renderer
)

//GetAllData all list
func GetAllData(c echo.Context) error {

	posts := []string{
		"Larry Ellison",
		"Carlos Slim Helu",
		"Mark Zuckerberg",
		"Amancio Ortega ",
		"Jeff Bezos",
		" Warren Buffet ",
		"Bill Gates",
		"selman tunç",
	}

	return c.Render(http.StatusOK, "templates/index.html",
		pongo2.Context{"title": "hello echo fw", "posts": posts})

}

func main() {
	e := echo.New()
	e.Renderer = mainRenderer //pongo2 init
	e.Debug = true
	// http://localhost:8888/home
	e.GET("/home", GetAllData)
	// Start server
	e.Logger.Fatal(e.Start(":8888"))
}

HTML


<h1> {{ title }}</h1>

{% for post in posts%}
<ul>
  <li>{{post}}</li>
</ul>
{% endfor %}

GoDoc

Specials Thanks

https://github.com/siredwin/pongorenderer Version 3

https://machiel.me/post/pongo2-with-echo-or-net-http/

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Renderer

type Renderer struct{ Debug bool }

Renderer : Custom Renderer for templates

func (Renderer) Render

func (r Renderer) Render(w io.Writer, name string, data interface{}, c echo.Context) error

Render : Custom renderer

Jump to

Keyboard shortcuts

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