parsing and templating improvements

This commit is contained in:
Henrique Dias
2015-09-14 14:00:12 +01:00
parent e9d507fec3
commit 0d9c1fa6ef
7 changed files with 46 additions and 57 deletions

5
templates/footer.tmpl Normal file
View File

@@ -0,0 +1,5 @@
{{ define "footer" }}
<footer></footer>
</body>
</html>
{{ end }}

View File

@@ -0,0 +1,11 @@
{{ define "frontmatter" }}
{{ range $key, $value := . }}
{{ if $value.SubContent }}
<h2>{{ splitCapitalize $value.Name }}</h2>
{{ template "frontmatter" $value.Content }}
{{ else}}
<label for="{{ $value.Master }}_{{ $value.Name }}">{{ splitCapitalize $value.Name }}</label>
<input name="{{ $value.Master }}_{{ $value.Name }}" id="{{ $value.Master }}_{{ $value.Name }}" value="{{ $value.Content }}"></input><br>
{{ end }}
{{ end }}
{{ end }}

View File

@@ -1,3 +1,4 @@
{{ define "header" }}
<!DOCTYPE html>
<html class="no-js" lang="en">
<head>
@@ -20,9 +21,4 @@
<header class="site-header">
Admin
</header>
{{ template "content" . }}
<footer></footer>
</body>
</html>
{{ end }}

View File

@@ -1,30 +1,12 @@
{{ define "optsLoop" }}
{{ range $key, $value := . }}
{{ if $value.SubContent }}
<h2>{{ splitCapitalize $value.Name }}</h2>
{{ template "optsLoop" $value.Content }}
{{ else}}
{{ template "header" . }}
<label for="{{ $value.Master }}_{{ $value.Name }}">{{ splitCapitalize $value.Name }}</label>
<input name="{{ $value.Master }}_{{ $value.Name }}" id="{{ $value.Master }}_{{ $value.Name }}" value="{{ $value.Content }}"></input><br>
{{ end }}
{{ end }}
{{ end }}
{{ define "content" }}
{{ with .Body }}
<div class="content">
<h1>Settings</h1>
<form>
{{ template "optsLoop" .Settings }}
{{ template "frontmatter" .Settings }}
</form>
</div>
{{ end }}
{{ end }}
{{ end }}
{{ template "footer" . }}