diff --git a/controller/routes.go b/controller/routes.go index d4018dd..1ed0035 100644 --- a/controller/routes.go +++ b/controller/routes.go @@ -69,12 +69,15 @@ func saveHandler(w http.ResponseWriter, r *http.Request, title string) { func renderTemplate(w http.ResponseWriter, tmpl string, p *model.Page) { // err := templates.ExecuteTemplate(w, "templates/"+tmpl+".html", p) - t, err := template.ParseFiles("templates/" + tmpl + ".html") + t, err := template.ParseFiles(getTmplName("base"), getTmplName(tmpl)) checkError(err, w) err = t.Execute(w, p) checkError(err, w) } +func getTmplName(tmpl string) string { + return tmplDir + tmpl + ".html" +} func checkError(err error, w http.ResponseWriter) { if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) diff --git a/controller/settings.go b/controller/settings.go index 06df662..cbef706 100644 --- a/controller/settings.go +++ b/controller/settings.go @@ -1,3 +1,4 @@ package controller var Port int = 8080 +var tmplDir string = "templates/" diff --git a/data/doc.txt b/data/doc.txt new file mode 100644 index 0000000..938475e --- /dev/null +++ b/data/doc.txt @@ -0,0 +1,7 @@ +Type a term in the search bar. + +If it already exist you will reach this page. + +If it is not yet defined you will have the possibility to create it. + +Have fun \ No newline at end of file diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 0000000..5e73351 --- /dev/null +++ b/templates/base.html @@ -0,0 +1,74 @@ + + + + + + + + + + {{template "title" .}} + + +
+ {{template "content" .}} +
+ + + + + + diff --git a/templates/edit.html b/templates/edit.html index faa9be4..71085ff 100644 --- a/templates/edit.html +++ b/templates/edit.html @@ -1,3 +1,4 @@ +{{define "title"}} {{.Title}} | Go-Wiki {{end}} {{define "content"}}

Editing {{.Title}}

@@ -6,3 +7,4 @@
+{{end}} diff --git a/templates/home.html b/templates/home.html index 6106acc..d99a8ba 100644 --- a/templates/home.html +++ b/templates/home.html @@ -1,5 +1,16 @@ -

Hi there, Welcome to Go-Wiki

+{{define "title"}} Welcome to Go-Wiki {{end}} {{define "content"}} -
-

Useful links

+
+

Welcome to Go-Wiki

+

+ Golang powered Wiki web application +

+
+

+ Look at our documentation to discover how to contribute ! +

+ Documentation
+{{end}} diff --git a/templates/view.html b/templates/view.html index b1e87ef..bed54b8 100644 --- a/templates/view.html +++ b/templates/view.html @@ -1,5 +1,7 @@ +{{define "title"}} {{.Title}} | Go-Wiki {{end}} {{define "content"}}

{{.Title}}

[edit]

{{printf "%s" .Body}}
+{{end}}