All Projects → dannyvankooten → Grender

dannyvankooten / Grender

Licence: mit
Go package for easily rendering JSON/XML data and HTML templates

Programming Languages

go
31211 projects - #10 most used programming language

Labels

Projects that are alternatives of or similar to Grender

Simple Reactjs App
Simple Application Using Basic React Components and Communication between them
Stars: ✭ 86 (-6.52%)
Mutual labels:  template
Webpack Defaults
Defaults to be shared across webpack projects
Stars: ✭ 88 (-4.35%)
Mutual labels:  template
Rebecca
Rebecca is a readme generator for Go
Stars: ✭ 91 (-1.09%)
Mutual labels:  template
Gomplate
A flexible commandline tool for template rendering. Supports lots of local and remote datasources.
Stars: ✭ 1,270 (+1280.43%)
Mutual labels:  template
Catesta
Catesta is a PowerShell module project generator. It uses templates to rapidly scaffold test and build integration for a variety of CI/CD platforms.
Stars: ✭ 88 (-4.35%)
Mutual labels:  template
Ghostwind
Tailwind CSS Starter Template - Ghostwind (Ghost Casper theme in Tailwind CSS)
Stars: ✭ 89 (-3.26%)
Mutual labels:  template
Swift Project Template
🍪 Easily generate Swift projects with Cookiecutter
Stars: ✭ 85 (-7.61%)
Mutual labels:  template
Androidbase
Android project template for Gradle Kotlin DSL + 100% Kotlin + Base module + Extensions = ❤️
Stars: ✭ 92 (+0%)
Mutual labels:  template
Placeline Nextjs
HyperTrack Placeline web application sample using NextJS, Ant-Design, Styled-Components, and Heroku
Stars: ✭ 88 (-4.35%)
Mutual labels:  template
Codrops Dropcast
a responsive HTML/CSS/Javascript template, comes with Sketch files and a fully working site with SCSS. It works very well for podcasts landing pages or blogs, and can be easily customized.
Stars: ✭ 91 (-1.09%)
Mutual labels:  template
Phaser3 Tilemap Pack
Phaser 3 Project Template with Webpack, Tilemap, and Asset Pack
Stars: ✭ 87 (-5.43%)
Mutual labels:  template
Svelte Pwa
Svelte Progresssive Web App (PWA) starter template
Stars: ✭ 87 (-5.43%)
Mutual labels:  template
Rebar3
Erlang build tool that makes it easy to compile and test Erlang applications and releases.
Stars: ✭ 1,295 (+1307.61%)
Mutual labels:  template
Boilr
⚡️ boilerplate template manager that generates files or directories from template repositories
Stars: ✭ 1,268 (+1278.26%)
Mutual labels:  template
Vertx Gradle Starter
Gradle project template for Vert.x
Stars: ✭ 91 (-1.09%)
Mutual labels:  template
Streamdecktoolkit
A .NET Standard library, template, and tools for building extensions to the Elgato Stream Deck
Stars: ✭ 85 (-7.61%)
Mutual labels:  template
Yipack Cli
易打包-命令行工具
Stars: ✭ 89 (-3.26%)
Mutual labels:  template
Monster
The Art of Template MetaProgramming (TMP) in Modern C++♦️
Stars: ✭ 90 (-2.17%)
Mutual labels:  template
Ghost Theme Template
A project scaffold for building ghost themes using gulp, node-sass, & autoprefixer
Stars: ✭ 91 (-1.09%)
Mutual labels:  template
Portfolio Template
An Open-Sourced Template for developers to show-off there skills. Made with ReactJS
Stars: ✭ 52 (-43.48%)
Mutual labels:  template

Grender GoDoc Build Status


Deprecation notice

This package could be more focused, so it was split up into two improved packages:


Grender is a package that provides functionality for easily rendering HTML templates and JSON or XML data to a HTTP response. It is based on github.com/unrolled/render with some subtle modifications when it comes to rendering HTML templates.

  • Templates inheritance: {{/* extends "master.tmpl" */}}
  • Glob configuration: templates/*.tmpl
  • Normal templates as partials: {{ template "footer" .}}

Usage

Grender can be used with pretty much any web framework providing you can access the http.ResponseWriter from your handler. The rendering functions simply wraps Go's existing functionality for marshaling and rendering data.

  • HTML: Uses the html/template package to render HTML templates.
  • JSON: Uses the encoding/json package to marshal data into a JSON-encoded response.
  • XML: Uses the encoding/xml package to marshal data into an XML-encoded response.
  • Text: Passes the incoming string straight through to the http.ResponseWriter.
// main.go
package main

import (
    "net/http"
    "github.com/dannyvankooten/grender"  
)

func main() {
    r := grender.New(grender.Options{
        Charset: "ISO-8859-1",
        TemplatesGlob: "examples/*.tmpl",
    })
    mux := http.NewServeMux()

    // This will set the Content-Type header to "application/json; charset=ISO-8859-1".
    mux.HandleFunc("/json", func(w http.ResponseWriter, req *http.Request) {
        r.JSON(w, http.StatusOK, map[string]string{"hello": "world"})
    })

    // This will set the Content-Type header to "text/html; charset=ISO-8859-1".
    mux.HandleFunc("/html", func(w http.ResponseWriter, req *http.Request) {
        r.HTML(w, http.StatusOK, "hello.tmpl", "world")
    })

    http.ListenAndServe("127.0.0.1:3000", mux)
}

Options

Grender comes with a variety of configuration options. The defaults are listed below.

r := grender.New(grender.Options{
    Debug: false,       // If true, templates will be recompiled before each render call
    TemplatesGlob: "",  // Glob to your template files
    PartialsGlob: "",   // Glob to your patials or global templates
    Funcs: nil,         // Your template FuncMap
    Charset: "UTF-8",   // Charset to use for Content-Type header values
})

Extending another template

First, define your parent template like this.

file: master.tmpl

<html>
  {{template "content" .}}
</html>

Then, in a separate template file use a template comment on the first line to indicate that you want to extend the other template file.

file: child.tmpl

{{/* extends "master.tmpl" */}}

{{define "content"}}Hello world!{{end}}

More examples

The grender_test.go file contains additional usage examples.

License

See LICENSE file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].