HTML template engine for Go

Related tags

Template Engines ace
Overview

Ace - HTML template engine for Go

wercker status GoDoc

Overview

Ace is an HTML template engine for Go. This is inspired by Slim and Jade. This is a refinement of Gold.

Example

= doctype html
html lang=en
  head
    title Hello Ace
    = css
      h1 { color: blue; }
  body
    h1 {{.Msg}}
    #container.wrapper
      p..
        Ace is an HTML template engine for Go.
        This engine simplifies HTML coding in Go web application development.
    = javascript
      console.log('Welcome to Ace');

becomes

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Hello Ace</title>
    <style type="text/css">
      h1 { color: blue; }
    </style>
  </head>
  <body>
    <h1>Hello Ace</h1>
    <div id="container" class="wrapper">
      <p>
        Ace is an HTML template engine for Go.<br>
        This engine simplifies HTML coding in Go web application development.
      </p>
    </div>
    <script type="text/javascript">
      console.log('Welcome to Ace');
    </script>
  </body>
</html>

Features

Making Use of the Go Standard Template Package

Ace fully utilizes the strength of the html/template package. You can embed actions of the template package in Ace templates. Ace also uses nested template definitions of the template package and Ace templates can pass pipelines (parameters) to other templates which they include.

Simple Syntax

Ace has a simple syntax and this makes template files simple and light.

Caching Function

Ace has a caching function which caches the result data of the templates parsing process. You can omit the templates parsing process and save template parsing time by using this function.

Binary Template Load Function

Ace has a binary template load function which loads Ace templates from binary data in memory instead of template files on disk. You can compile your web application into one binary file by using this function. go-bindata is the best for generating binary data from template files.

Getting Started

Please check the following documentation.

  • Getting Started - shows the getting started guide.
  • Examples - shows the examples of the web applications which use the Ace template engine.

Documentation

You can get the documentation about Ace via the following channels:

  • Documentation - includes the getting started guide and the syntax documentation.
  • GoDoc - includes the API documentation.

Discussion & Contact

You can discuss Ace and contact the Ace development team via the following channels:

Contributions

Any contributions are welcome. Please feel free to create an issue or send a pull request.

Renderers for web frameworks

Tools

  • vim-ace - Vim syntax highlighting for Ace templates
  • ace-tmbundle - TextMate/Sublime syntax highlighting for Ace templates
  • atom-ace - Atom Editor syntax highlighting for Ace templates

Projects using Ace

Here is the list of the projects using Ace. Please feel free to add your awesome project to the list!

Comments
  • Option for closing tags list

    Option for closing tags list

    Ace has predefined list of tag names to NOT be closed. It's handy to have an option to provide the list. If I'm producing XML, I'd have it empty.

    Code changes notes:

    • The list is kept in a map[string]struct{} as the size of struct{} is zero.
    • Initializing func makes a copy of defaultNoCloseTagNames for opts.NoCloseTagNames, otherwise plain assignment would create a reference to the default (as it is a map) and it could be modified outside ace.

    I also took the opportunity to make initializeOptions public. It becomes complex to re-do what the func does in non-ace code when it passes non-nil *ace.Options to ace.Load etc.

    opened by ostness 8
  • Setting Variables in Child Template

    Setting Variables in Child Template

    How to set variable? For example, if I want to set a title variable from a child template to be used in a parent template, how can I do that? I remember with Gold it was quite easy because of the optional blocks.

    opened by dre1080 7
  • ace breaks when attributes have =

    ace breaks when attributes have =

    meta http-equiv=Content-Type content="text/html;charset=UTF-8"
    meta name=viewport content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"
    

    When an attribute has an equals sign in its value, ace seems to be breaking. Is there something I need to do?

    opened by nelsonpecora 6
  • Overridable

    Overridable "class" attribute

    I'm compiling ace templates for React's jsx(1) to transform html blocks into React classes. Being JavaScript code and all, the "class" attribute becomes a keyword and must be written as "className". That's an explicit requirement of React.

    This shouldn't be an option in ace, I'll be fine with the attributeNameClass redeclared as a var and made public. ace.AttributeNameClass = "className" in my code would do the trick.

    opened by ostness 4
  • The API is complicated.

    The API is complicated.

    First of all, thanks a lot for this package, as someone who really likes Jade I totally appreciate this project.

    But the current API is over complicated. A similar api to the original http/template would be great, or at least something with the similar level of abstraction.

    If I want to compile a template, I just want.

    ace.Compile([]byte, map[string][]byte) *html.Template
    

    And I would be happy.

    And when working with Go templates, something like this would be ideal.

    ace.Template(*template.Template, string. []byte)
    

    And I would be happy if you parsed/compiled my []byte and stick it in the template.Temlate under the name supplied by string.

    Of course, the map[string][]bytes holds the includes.

    opened by omeid 4
  • Ace breaks when using tabs

    Ace breaks when using tabs

    Hi,

    I do not know if this is an issue but I notice when I am using tabspaces, the rendering would break while for whitespaces it doesnt. When using tabs with one of the examples, it outputs

    < head></ head>< meta charset="utf-8"></ meta>< title>HTML Tags</ title>< body></ body>< header></ header>< h1>HTML Tags</ h1>< section id="main-section" class="class1 class2 class3"></ section>< id="container"></ >< class="wrapper"></ >< div>Single text line can follow the tag name.</ div>< p> </ p>< This>is a block text.</ This>< BR>tags are inserted automatically.</ BR>< a href="https://github.com">Go to GitHub</ a>< input type="checkbox" checked></ input>< footer></ footer>< script> </ script>< var>msg = 'Hello Ace';</ var>< alert(msg);></ alert(msg);>

    with the html itself looking like

    < head></ head>< meta charset="utf-8"></ meta>< title>HTML Tags</ title>< body></ body>< header></ header>< h1>HTML Tags</ h1>< section id="main-section" class="class1 class2 class3"></ section>< id="container"></ >< class="wrapper"></ >< div>Single text line can follow the tag name.</ div>< p>

    </ p>< This>is a block text.</ This>< BR>tags are inserted automatically.</ BR>< a href="https://github.com">Go to GitHub</ a>< input type="checkbox" checked></ input>< footer></ footer>< script> </ script>< var>msg = 'Hello Ace';</ var>< alert(msg);></ alert(msg);>

    (Sorry for the paste like this, pastebin and hastebin been acting up for me this current hour)

    opened by dariusc93 4
  • Create 0.0.5 tag

    Create 0.0.5 tag

    Hello,

    Would it be possible to release a new tag for this library? Ace API has evolved significantly since tag 0.0.4 in 2014.

    To give you more context, we'd like to package this library for Fedora. However, as the static site generator Hugo depends on commit ea038f4 of ace (cf. https://github.com/spf13/hugo/blob/ea165bf/vendor/vendor.json#L328), we'd like to package a recent release of the library. Specifically, Hugo uses ace.CompileResultWithTemplate which is not available in the latest tag 0.0.4.

    Thank you!

    opened by olivierlemasle 3
  • Referencing a struct within a range

    Referencing a struct within a range

    I'm ranging over a slice but I want to enable some functions if the object is accessible by the currently logged in user (just visually).

    <% range .Projects %>
        ...
        <% if eq .CurrentUser.Id .User.Id %>
           ...
        <% end %>
    <% end %>
    

    This gives me this error:

    template: views/base:views/application/index:1:436: executing "views/application/index::main" at <.CurrentUser.Id>: CurrentUser is not a field of struct type models.Project
    

    Question: How do I refence a variable that is outside of the range scope? Or how could I implement the desired behaviour?

    opened by sebastiandeutsch 3
  • Sort HTML attributes by key

    Sort HTML attributes by key

    HTML attributes are backed by a Go map, and since Go 1 the iteration order has been random.

    This is not a problem for the browsers, but is a problem when using changed content as a way of detecting which files to deploy to a server.

    This commit fixes that by ordering by attribute key.

    Fixes #37

    opened by bep 3
  • Don't ignore basePath when loading bytes directly with Asset option

    Don't ignore basePath when loading bytes directly with Asset option

    I'm writing an application using ace, and it would be great if I could load a template by passing in bytes directly instead of loading a file. (I have some files which contain front matter, so I only want ace to compile the part after the front matter).

    Currently, I can almost do what I want to do by using the Asset option. Here's my code:

    main.go:

    // ...
    srcBytes := []byte(`= content main
      h1 hello`)
    tpl, err := ace.Load("base", "", &ace.Options{
        Asset: func(name string) ([]byte, error) {
            return srcBytes, nil
        },
    })
    // ...
    

    base.ace:

    = doctype html
    html lang=en
      head
        = include _includes/head .
      body
        #container
          = yield main
    

    The problem is that ace ignores base.ace and instead tries to render the bytes directly. Since = content main has no corresponding = yield main, what I get is a blank page. What I want is the bytes to be rendered as an inner template of base.ace, so the resulting html should be this:

    <doctype html>
    <html>
        <head>
            <!-- stuff from _includes/head here -->
        </head>
        <body>
            <div id="container">
                <h1>Hello</h1>
            </div>
        </body>
    </html>
    

    I'm working on a pull request which will accomplish just that. Doesn't look too hard.

    opened by albrow 3
  • link style attributes

    link style attributes

    What is the correct way to add stylesheet links to the head tag using ace? So far I've tried adding the following the the getting started example after title:

    link rel="stylesheet" href="assets/css/style.css"
    

    ...

    link rel="stylesheet", href="assets/css/style.css"
    

    ...

    link(rel="stylesheet", href="assets/css/style.css")
    

    All yield: PANIC: the indent is invalid [file: views/base.ace][line: 7]

    opened by michael4reynolds 3
  • How to set

    How to set "selected" in select tag?

    I would like to do something like this:

    select name="a"
      option value="alice" selected={{.IsAlice}} Alice
      option value="bob" selected={{.IsBob}} Bob
    

    Is it possible?

    opened by Paxa 0
  • Are conditionals possible?

    Are conditionals possible?

    In Haml, Slim, Slang I'm used to the following.

    - if name.size > 10
      | You have a long name.
    - else
      | You're name is average.
    

    Is there anyway to achieve something similar with Ace?

    opened by elorest 1
  • How to include underscore (or other) templates OR: how to add id to = javascript

    How to include underscore (or other) templates OR: how to add id to = javascript

    I am currently trying to include an underscore template using ace. I need to give 1. an id to the script and it should not be escaped...

    This is the template:

    <script type="text/template" id="result-row">
        {% _.each(results, function(result,key,arr) { %}
            <tr onclick="getBook( {%= result.id %} )">
                <td>{%= result.id %}</td>
                <td>{%= result.title %}</td>
                <td>{%= result.author%}</td>
                <td>{%= result.year%}</td>
            </tr>
        {% }); %}
    </script>
    

    The script tag

    If I use the script tag, I can assign a id attribute, like this:

    script id="result-row" type="text/javascript"

    But this results in the "<" and ">" beeing escaped and tags added like this:

    <script id="result-row" type="text/javascript"><{%>_.each(results, function(result,key,arr) { %}<<tr onclick=""getBook( {%= result.id %} )">"><<td>{%=>result.id %}</td></<td>{%=><<td>{%=>result.title %}</td></<td>{%=><<td>{%=>result.author%}</td></<td>{%=><<td>{%=>result.year%}</td></<td>{%=></<tr><</tr>></</tr>></{%><{%>}); %}</{%></script>
    

    Using the = javascript syntax

    In this case all is fine. Exept: I am not able to assign an id to the javascript element. Beeig able to add attributes to = javascript would actually fix this

    opened by th-lange 0
  • Support for colon in attribute names

    Support for colon in attribute names

    Would it be possible to add support for colons in attribute names, for use with JavaScript frameworks like Vue.js?

    E.g. v-bind:items="something"

    At present printed inside the tag and not as an attribute.

    opened by liilac 0
Releases(v0.0.5)
Owner
Keiji Yoshida
Keiji Yoshida
Wrapper package for Go's template/html to allow for easy file-based template inheritance.

Extemplate Extemplate is a small wrapper package around html/template to allow for easy file-based template inheritance. File: templates/parent.tmpl <

Danny van Kooten 51 Dec 6, 2022
Goview is a lightweight, minimalist and idiomatic template library based on golang html/template for building Go web application.

goview Goview is a lightweight, minimalist and idiomatic template library based on golang html/template for building Go web application. Contents Inst

foolin 314 Dec 25, 2022
A template to build dynamic web apps quickly using Go, html/template and javascript

gomodest-template A modest template to build dynamic web apps in Go, HTML and sprinkles and spots of javascript. Why ? Build dynamic websites using th

Adnaan Badr 85 Dec 29, 2022
HTML template engine for Go

Ace - HTML template engine for Go Overview Ace is an HTML template engine for Go. This is inspired by Slim and Jade. This is a refinement of Gold. Exa

Keiji Yoshida 827 Jan 4, 2023
Package damsel provides html outlining via css-selectors and common template functionality.

Damsel Markup language featuring html outlining via css-selectors, extensible via pkg html/template and others. Library This package expects to exist

Daniel Skinner 24 Oct 23, 2022
Golang Echo and html template.

golang-website-example Golang Echo and html template. move GitHub repository for hello to golang-website-example Visual Studio Code Run and Debug: lau

Ocki Bagus Pratama 0 Feb 4, 2022
Made from template temporalio/money-transfer-project-template-go

Temporal Go Project Template This is a simple project for demonstrating Temporal with the Go SDK. The full 20 minute guide is here: https://docs.tempo

MarkGorewicz 0 Jan 6, 2022
Go-project-template - Template for a golang project

This is a template repository for golang project Usage Go to github: https://git

KyberNetwork 4 Oct 25, 2022
Go-api-template - A rough template to give you a starting point for your API

Golang API Template This is only a rough template to give you a starting point f

Only Tunes Radio 3 Jan 14, 2022
Api-go-template - A simple Go API template that uses a controller-service based model to build its routes

api-go-template This is a simple Go API template that uses a controller-service

Pedro Espíndula 1 Feb 18, 2022
Simple and fast template engine for Go

fasttemplate Simple and fast template engine for Go. Fasttemplate performs only a single task - it substitutes template placeholders with user-defined

Aliaksandr Valialkin 672 Dec 30, 2022
A handy, fast and powerful go template engine.

Hero Hero is a handy, fast and powerful go template engine, which pre-compiles the html templates to go code. It has been used in production environme

Lime 1.5k Dec 27, 2022
Jet template engine

Jet Template Engine for Go Jet is a template engine developed to be easy to use, powerful, dynamic, yet secure and very fast. simple and familiar synt

null 984 Jan 4, 2023
A complete Liquid template engine in Go

Liquid Template Parser liquid is a pure Go implementation of Shopify Liquid templates. It was developed for use in the Gojekyll port of the Jekyll sta

Oliver Steele 188 Dec 15, 2022
gtpl is a template engine for glang

gtpl 使用必读 gtpl is a HTML template engine for golang gtpl 是一个 go 语言模板引擎,它能以极快的速度进行模板语法分析。相比 go 语言官方库 html/template,gtpl 的语法有着简练、灵活、易用的特点。

null 6 Nov 28, 2022
The world’s most powerful template engine and Go embeddable interpreter.

The world’s most powerful template engine and Go embeddable interpreter

Open2b 372 Dec 23, 2022
This my project template for making fiber with SSR taste by empowered mustache engine.

SSR-FIBER-TEMPLATE This my project template for making fiber with SSR taste by empowered mustache engine. Folder Hierarchy Name Description configs Co

▲ 2 May 9, 2022
Templating system for HTML and other text documents - go implementation

FAQ What is Kasia.go? Kasia.go is a Go implementation of the Kasia templating system. Kasia is primarily designed for HTML, but you can use it for any

Michał Derkacz 74 Mar 15, 2022
Safe HTML for Go

Safe HTML for Go safehtml provides immutable string-like types that wrap web types such as HTML, JavaScript and CSS. These wrappers are safe by constr

Google 293 Dec 28, 2022