Skip to content

Commit b57ef91

Browse files
committed
chore: change the order of sections
1 parent a41c3bd commit b57ef91

2 files changed

Lines changed: 44 additions & 43 deletions

File tree

versioned_docs/version-v1/get-started/template-usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,4 @@ Let's take a look at the example how I would define a `home.tw.html` and then I'
9999
- Then we insert the title into layout with the value "Home page"
100100
- Then we insert the content into layout with the HTML body.
101101

102-
You can read more about [use](/docs/v1/language-elements/statements#use-statement), [insert](/docs/v1/language-elements/statements#insert-statement) and [reserve](/docs/v1/language-elements/statements#reserve-statement) statements on the [statements](/docs/v1/language-elements/statements) page if you need more information about the syntax.
102+
You can read more about [use](/docs/v1/language-elements/statements#use-statement), [insert](/docs/v1/language-elements/statements#insert-statement) and [reserve](/docs/v1/language-elements/statements#reserve-statement) statements on the [statements](/docs/v1/language-elements/statements) page if you need more information about the syntax.

versioned_docs/version-v2/guides/template-usage.md

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func main() {
2929
fmt.Println(err)
3030
}
3131

32-
http.HandleFunc("/", homeView)
32+
http.HandleFunc("/", homeHandler)
3333

3434
http.ListenAndServe(":8080", nil)
3535
}
@@ -42,50 +42,11 @@ Non of the configurations are required, because each configuration has a default
4242

4343
In return from the `NewTemplate` function, we get a `Template` object that can be used to evaluate an already parsed template.
4444

45-
## Configuration
46-
There are a few configurations that you can pass to the `NewTemplate` function to configure the template language. The `NewTemplate` function accepts a `*config.Config` with several properties.
47-
48-
There are cases when you want to override the default file format or the directory where the template files are stored. Here is an example of how you can configure the template language:
49-
50-
```go title="main.go"
51-
import (
52-
"fmt"
53-
"net/http"
54-
55-
"github.com/textwire/textwire/v2"
56-
// highlight-next-line
57-
"github.com/textwire/textwire/v2/config"
58-
)
59-
60-
var tpl *textwire.Template
61-
62-
func main() {
63-
var err error
64-
65-
// highlight-start
66-
tpl, err = textwire.NewTemplate(&config.Config{
67-
TemplateDir: "src/templates",
68-
TemplateExt: ".tw", // recommended to use .tw extension
69-
})
70-
// highlight-end
71-
72-
if err != nil {
73-
fmt.Println(err)
74-
}
75-
76-
http.HandleFunc("/", homeView)
77-
78-
http.ListenAndServe(":8080", nil)
79-
}
80-
```
81-
82-
To read more about the available configurations, visit the [configurations](/docs/v2/guides/configurations) page.
83-
8445
## Write response to the client
8546
You can use the `Response` method on `Template` object to write the evaluated template to the client. The `Response` method accepts a `http.ResponseWriter` object, the name of the template file, and a map of variables that you want to inject into the template. Here is an example:
8647

8748
```go title="main.go"
88-
func homeView(w http.ResponseWriter, r *http.Request) {
49+
func homeHandler(w http.ResponseWriter, r *http.Request) {
8950
err := tpl.Response(w, "home", map[string]interface{}{
9051
"title": "Home page",
9152
"names": []string{"John", "Jane", "Jack", "Jill"},
@@ -140,4 +101,44 @@ Let's take a look at the example how I would define a `home.tw.html` and then I'
140101
- Then we insert the title into layout with the value "Home page"
141102
- Then we insert the content into layout with the HTML body.
142103

143-
You can read more about [use](/docs/v2/language-elements/statements#use-statement), [insert](/docs/v2/language-elements/statements#insert-statement) and [reserve](/docs/v2/language-elements/statements#reserve-statement) statements on the [statements](/docs/v2/language-elements/statements) page if you need more information about the syntax.
104+
You can read more about [use](/docs/v2/language-elements/statements#use-statement), [insert](/docs/v2/language-elements/statements#insert-statement) and [reserve](/docs/v2/language-elements/statements#reserve-statement) statements on the [statements](/docs/v2/language-elements/statements) page if you need more information about the syntax.
105+
106+
## Configuration
107+
There are a few configurations that you can pass to the `NewTemplate` function to configure the template language. The `NewTemplate` function accepts a `*config.Config` with several properties.
108+
109+
There are cases when you want to override the default file format or the directory where the template files are stored. Here is an example of how you can configure the template language:
110+
111+
```go title="main.go"
112+
import (
113+
"fmt"
114+
"net/http"
115+
116+
"github.com/textwire/textwire/v2"
117+
// highlight-next-line
118+
"github.com/textwire/textwire/v2/config"
119+
)
120+
121+
var tpl *textwire.Template
122+
123+
func main() {
124+
var err error
125+
126+
// highlight-start
127+
tpl, err = textwire.NewTemplate(&config.Config{
128+
TemplateDir: "src/templates",
129+
TemplateExt: ".tw", // recommended to use .tw extension
130+
})
131+
// highlight-end
132+
133+
if err != nil {
134+
fmt.Println(err)
135+
}
136+
137+
http.HandleFunc("/", homeHandler)
138+
139+
http.ListenAndServe(":8080", nil)
140+
}
141+
```
142+
143+
To read more about the available configurations, visit the [configurations](/docs/v2/guides/configurations) page.
144+

0 commit comments

Comments
 (0)