Skip to content

Instantly share code, notes, and snippets.

@techslides
Last active August 29, 2015 13:55
Show Gist options
  • Select an option

  • Save techslides/8760665 to your computer and use it in GitHub Desktop.

Select an option

Save techslides/8760665 to your computer and use it in GitHub Desktop.
Passing variable for custom title to layout.html template in Martini
//inside Martini GET function m.Get("/", func(r render.Render) {...
//newmap := map[string]interface{}{"metatitle": "this is custom title for SEO", "posts": posts}
//r.HTML(200, "posts", newmap)
//layout.tmpl
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{.metatitle}}</title>
<!-- Add custom CSS here -->
<link href="/css/main.css" rel="stylesheet">
</head>
<body>
{{yield}}
<!-- JavaScript -->
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="/js/main.js"></script>
</body>
</html>
//posts.tmpl
{{range .posts}}
<h3><a href="/{{ .Id }}">{{ .Title }}</a></h3>
<small>{{.Created | formatTime}}</small>
<div>{{ .Body }}</div>
{{end}}
<h2>Create a Post</h2>
<form action="/" method="POST">
<input type="text" name="Title" placeholder="Title" /><br>
<textarea name="Body"></textarea><br>
<input type="submit" value="submit"/>
</form>
@techslides
Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment