mirror of
https://github.com/arnaucube/konstrui.git
synced 2026-02-07 03:26:43 +01:00
added possibility to template i count
This commit is contained in:
30
README.md
30
README.md
@@ -3,7 +3,7 @@
|
|||||||
web templating engine for static websites, written in Go lang
|
web templating engine for static websites, written in Go lang
|
||||||
|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
@@ -41,9 +41,9 @@ webInput/
|
|||||||
- Set the template file:
|
- Set the template file:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<div class="class1">
|
<div class="class1" id="user[[i]]">
|
||||||
<div class="class2">{{username}}</div>
|
<div id="username[[i]]" class="class2">{{username}}</div>
|
||||||
<div class="class2">{{description}}</div>
|
<div id="description[[i]]" class="class2">{{description}}</div>
|
||||||
<div class="class2">{{phone}}</div>
|
<div class="class2">{{phone}}</div>
|
||||||
</div>
|
</div>
|
||||||
```
|
```
|
||||||
@@ -99,21 +99,21 @@ webInput/
|
|||||||
<html>
|
<html>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<h1>My First Heading</h1>
|
<h1>Heading</h1>
|
||||||
<p>My first paragraph.</p>
|
<p>Paragraph.</p>
|
||||||
<div class="class1">
|
<div class="class1" id="user0">
|
||||||
<div class="class2">Michaela Doe</div>
|
<div id="username0" class="class2">Michaela Doe</div>
|
||||||
<div class="class2">Hi, I'm here to code</div>
|
<div id="description0" class="class2">Hi, I'm here to code</div>
|
||||||
<div class="class2">456456456</div>
|
<div class="class2">456456456</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="class1">
|
<div class="class1" id="user1">
|
||||||
<div class="class2">John Doe</div>
|
<div id="username1" class="class2">John Doe</div>
|
||||||
<div class="class2">Hi, I'm here</div>
|
<div id="description1" class="class2">Hi, I'm here</div>
|
||||||
<div class="class2">123456789</div>
|
<div class="class2">123456789</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="class1">
|
<div class="class1" id="user2">
|
||||||
<div class="class2">Myself</div>
|
<div id="username2" class="class2">Myself</div>
|
||||||
<div class="class2">How are you</div>
|
<div id="description2" class="class2">How are you</div>
|
||||||
<div class="class2">no phone</div>
|
<div class="class2">no phone</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -50,6 +51,7 @@ func generateFromTemplateAndData(templateContent string, entries []dataEntry) st
|
|||||||
//now, replace the keys with the values
|
//now, replace the keys with the values
|
||||||
for j := 0; j < len(keys); j++ {
|
for j := 0; j < len(keys); j++ {
|
||||||
entryContent = strings.Replace(entryContent, "{{"+keys[j]+"}}", entries[i][keys[j]], -1)
|
entryContent = strings.Replace(entryContent, "{{"+keys[j]+"}}", entries[i][keys[j]], -1)
|
||||||
|
entryContent = strings.Replace(entryContent, "[[i]]", strconv.Itoa(i), -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
newContent = newContent + entryContent
|
newContent = newContent + entryContent
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 110 KiB After Width: | Height: | Size: 110 KiB |
|
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 72 KiB |
Reference in New Issue
Block a user