Skip to content

Commit

Permalink
Merge pull request #8 from UniversityRadioYork/mw-template-blocks
Browse files Browse the repository at this point in the history
Template blocks
  • Loading branch information
ChrisTheBaron committed Apr 25, 2016
2 parents 553d75d + 6cfc66f commit 2f9e94b
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 73 deletions.
5 changes: 3 additions & 2 deletions controllers/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ func (ic *IndexController) Get(w http.ResponseWriter, r *http.Request) {
PageData: data,
}

t := template.New("index.tmpl") // Create a template.
t := template.New("base.tmpl") // Create a template.
t, err = t.ParseFiles(
"views/index.tmpl",
"views/partials/header.tmpl",
"views/partials/footer.tmpl",
"views/elements/navbar.tmpl",
"views/partials/base.tmpl",
"views/index.tmpl",
) // Parse template file.

if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions controllers/not_found.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ func (sc *NotFoundController) Get(w http.ResponseWriter, r *http.Request) {

w.WriteHeader(404)

t := template.New("404.tmpl") // Create a template.

t := template.New("base.tmpl") // Create a template.
t, err := t.ParseFiles(
"views/404.tmpl",
"views/partials/footer.tmpl",
"views/partials/header.tmpl",
"views/elements/navbar.tmpl",
"views/partials/base.tmpl",
"views/404.tmpl",
) // Parse template file.

if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions controllers/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ func (sc *SearchController) Get(w http.ResponseWriter, r *http.Request) {
}


t := template.New("search.tmpl") // Create a template.
t := template.New("base.tmpl") // Create a template.
t, err = t.ParseFiles(
"views/search.tmpl",
"views/partials/header.tmpl",
"views/partials/footer.tmpl",
"views/elements/navbar.tmpl",
"views/partials/base.tmpl",
"views/search.tmpl",
) // Parse template file.

if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions controllers/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ func (sc *ShowController) GetShow(w http.ResponseWriter, r *http.Request) {
},
}

t := template.New("show.tmpl") // Create a template.
t := template.New("base.tmpl") // Create a template.
t, err = t.ParseFiles(
"views/show.tmpl",
"views/partials/header.tmpl",
"views/partials/footer.tmpl",
"views/elements/navbar.tmpl",
"views/partials/base.tmpl",
"views/show.tmpl",
) // Parse template file.

if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions views/404.tmpl
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{template "header" .}}
{{define "content"}}
404: Not Found
{{template "footer" .}}
{{end}}
7 changes: 2 additions & 5 deletions views/index.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
</p>
{{end}}


{{template "header" .}}

{{define "content"}}
{{with .PageData}}

<div class="container">
Expand All @@ -29,5 +27,4 @@
</div><!-- /.container -->

{{end}}

{{template "footer" .}}
{{end}}
56 changes: 56 additions & 0 deletions views/partials/base.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>{{block "title" .}}{{.PageContext.LongName}}{{end}}</title>

<!-- bower:css -->
<link rel='stylesheet' href='/bower_components/bootstrap/dist/css/bootstrap.css' />
<!-- endbower -->

<link href='/styles/main.css' rel='stylesheet' type='text/css'>

<!-- @TODO: Move these into bower -->
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->

</head>
<body>

{{template "header" .}}

<br>
<br>
<br>
<br>
<br>
<br>

{{block "content" .}}
<div class="container">
<h1>Error</h1>
<p>No content defined for this page.</p>
</div>
{{end}}

{{template "footer" .}}

<!-- bower:js -->
<script src="/bower_components/modernizr/modernizr.js"></script>
<script src="/bower_components/jquery/dist/jquery.js"></script>
<script src="/bower_components/bootstrap/dist/js/bootstrap.js"></script>
<script src="/bower_components/moment/moment.js"></script>
<script src="/bower_components/jquery-ui/jquery-ui.js"></script>
<!-- endbower -->

<script src="scripts/main.min.js"></script>

</body>
</html>
14 changes: 0 additions & 14 deletions views/partials/footer.tmpl
Original file line number Diff line number Diff line change
@@ -1,16 +1,2 @@
{{define "footer"}}

<!-- bower:js -->
<script src="/bower_components/modernizr/modernizr.js"></script>
<script src="/bower_components/jquery/dist/jquery.js"></script>
<script src="/bower_components/bootstrap/dist/js/bootstrap.js"></script>
<script src="/bower_components/moment/moment.js"></script>
<script src="/bower_components/jquery-ui/jquery-ui.js"></script>
<!-- endbower -->

<script src="scripts/main.min.js"></script>

</body>
</html>

{{end}}
35 changes: 0 additions & 35 deletions views/partials/header.tmpl
Original file line number Diff line number Diff line change
@@ -1,38 +1,3 @@
{{define "header"}}

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>{{.PageContext.LongName}}</title>

<!-- bower:css -->
<link rel='stylesheet' href='/bower_components/bootstrap/dist/css/bootstrap.css' />
<!-- endbower -->

<link href='styles/main.css' rel='stylesheet' type='text/css'>

<!-- @TODO: Move these into bower -->
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->

</head>
<body>

{{template "navbar" .}}

<br>
<br>
<br>
<br>
<br>
<br>

{{end}}
6 changes: 2 additions & 4 deletions views/search.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{{template "header" .}}

{{define "content"}}
{{with .PageData}}

<div class="container">
Expand Down Expand Up @@ -43,5 +42,4 @@
</div><!-- /.container -->

{{end}}

{{template "footer" .}}
{{end}}
6 changes: 2 additions & 4 deletions views/show.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{{template "header" .}}

{{define "content"}}
{{with .PageData}}

<div class="container">
Expand All @@ -21,5 +20,4 @@
</div><!-- /.container -->

{{end}}

{{template "footer" .}}
{{end}}

0 comments on commit 2f9e94b

Please sign in to comment.