hugo/docs/content/layout/chrome.md

2.7 KiB

title date groups groups_weight
Chrome Templates 2013-07-01
layout
80

Chrome is a convention to create templates that are used by the other templates throughout the site. There is nothing special about the name "chrome", feel free to provide and use your own.

It's not a requirement to have this, but in practice it's very convenient. Hugo doesn't know anything about Chrome, it's simply a convention that you may likely find beneficial. As you create the rest of your templates you will include templates from the /layout/chrome directory.

I've found it helpful to include a header and footer template in Chrome so I can include those in the other full page layouts (index.html, indexes/ type/single.html). There is nothing special about header.html and footer.html other than they seem like good names to use for inclusion in your other templates.

▾ layouts/
  ▾ chrome/
      header.html
      footer.html

By ensuring that we only reference variables variables used for both nodes and pages we can use the same chrome for both.

example header.html

This header template is used for spf13.com.

{{% highlight html %}}

<html class="no-js" lang="en-US" prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb#"> <head>
{{ template "chrome/meta.html" . }}

<base href="{{ .Site.BaseUrl }}">
<title> {{ .Title }} : spf13.com </title>
<link rel="canonical" href="{{ .Permalink }}">
{{ if .RSSlink }}<link href="{{ .RSSlink }}" rel="alternate" type="application/rss+xml" title="{{ .Title }}" />{{ end }}

{{ template "chrome/head_includes.html" . }}
</head> {{% /highlight %}}

This header template is used for spf13.com.

{{% highlight html %}}

© 2013 Steve Francia. Some rights reserved; please attribute properly and link back. Hosted by ServerGrove.

</html> {{% /highlight %}}

For examples of referencing these templates, see content templates and homepage templates