added variable templating, template parts
This commit is contained in:
@ -47,19 +47,42 @@ func Template_with_page_vars(str string, tags_and_variables map[string]string) s
|
||||
|
||||
func Template_of_tag(str string, html_tag string) string {
|
||||
tag, err := os.ReadFile("web/views/tag/" + html_tag + ".html")
|
||||
result := strings.Replace(string(tag), "<fnr>", str, 1)
|
||||
result := strings.Replace(string(tag), "{{fnr}}", str, 1)
|
||||
lib.Handle_err(err, lib.Map_args("die", "1"))
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func Template_with_part(part_name string) string {
|
||||
head, err := os.ReadFile("web/views/head.html")
|
||||
lib.Handle_err(err, lib.Map_args("die", "1"))
|
||||
page, err := os.ReadFile("web/views/part/" + part_name + ".html")
|
||||
lib.Handle_err(err, lib.Map_args("die", "1"))
|
||||
foot, err := os.ReadFile("web/views/foot.html")
|
||||
lib.Handle_err(err, lib.Map_args("die", "1"))
|
||||
|
||||
template := "" + string(head) + string(page) + string(foot)
|
||||
fmt.Println(err)
|
||||
|
||||
return template
|
||||
}
|
||||
|
||||
func templating(file string, tag string, variable string) string {
|
||||
content, err := os.ReadFile("web/views/" + file + ".html")
|
||||
lib.Handle_err(err, lib.Map_args("die", "1"))
|
||||
|
||||
find_tag := `<` + tag + `>`
|
||||
find_tag := `{{` + tag + `}}`
|
||||
|
||||
template_result := strings.Replace(string(content), find_tag, variable, 1)
|
||||
|
||||
return template_result
|
||||
}
|
||||
|
||||
func Put_vars_to_template(template string, vars map[string]string) string {
|
||||
for key, value := range vars {
|
||||
fmt.Print(key, value)
|
||||
template = strings.Replace(template, "{{"+key+"}}", value, 1)
|
||||
}
|
||||
|
||||
return template
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user