Skip to content

6 Templates

Anthony HAMON edited this page Dec 13, 2017 · 1 revision

Chyle uses go template as template engine, documentation can be found in godoc here.

Let's have an example using the following release generated using JSON format :

{
  "datas": [
    {
      "authorDate": "2017-05-10 22:24:40 +0200 +0200",
      "authorEmail": "[email protected]",
      "authorName": "Anthony HAMON",
      "committerDate": "2017-05-10 22:24:40 +0200 +0200",
      "committerEmail": "[email protected]",
      "committerName": "GitHub",
      "date": "2017-05-10 22:24:40",
      "githubIssueId": 3,
      "githubTitle": "Test2",
      "id": "f617fb708dfa6fa290205615ea98c53a860e499d",
      "message": "Merge pull request #3 from antham/test2\n\nTest2",
      "type": "merge"
    },
    {
      "authorDate": "2017-05-10 22:22:03 +0200 +0200",
      "authorEmail": "[email protected]",
      "authorName": "Anthony HAMON",
      "committerDate": "2017-05-10 22:22:03 +0200 +0200",
      "committerEmail": "[email protected]",
      "committerName": "GitHub",
      "date": "2017-05-10 22:22:03",
      "githubIssueId": 1,
      "githubTitle": "Whatever",
      "id": "8fdfae00cbcc66936113a60f5146d110f2ba3c28",
      "message": "Merge pull request #1 from antham/test\n\nTest",
      "type": "merge"
    }
  ],
  "metadatas": {
    "date": "jeu. mai 18 23:01:25 CEST 2017"
  }
}

If we want to display a markdown release with the list of pull request title and their authors we can do :

### Release

{{ range $key, $value := .Datas }} ({{ $value.authorName }}) {{ end }}

Generated at {{ .Metadatas.date }}

We get :

### Release

Test2 (Anthony HAMON)
Whatever (Anthony HAMON)
Generated at jeu. mai 18 23:01:25 CEST 2017%

To provide more functionalities to original golang template, sprig library is provided, it gives several useful additional helpers, documentation can be found here.

For the sake of convenience, a custom global store is available as well, as templates cannot mutate defined variables : you can store a data using {{ set "key" "data"}}, you can retrieve a data using {{ get "key" }}, you can test if a key is set using {{ isset "key" }}.

Clone this wiki locally