From 667e11c4ec3835d959aab1797647bd0a49869674 Mon Sep 17 00:00:00 2001 From: etienne Date: Tue, 21 Oct 2014 23:35:24 +0200 Subject: Init commit --- content/templates/partials.md | 103 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 content/templates/partials.md (limited to 'content/templates/partials.md') diff --git a/content/templates/partials.md b/content/templates/partials.md new file mode 100644 index 0000000..e5a4186 --- /dev/null +++ b/content/templates/partials.md @@ -0,0 +1,103 @@ +--- +aliases: +- /layout/chrome/ +date: 2013-07-01 +menu: + main: + parent: layout +next: /templates/rss +prev: /templates/views +title: Partial Templates +weight: 80 +--- + +In practice, it's very convenient to split out common template portions into a +partial template that can be included anywhere. As you create the rest of your +templates, you will include templates from the /layout/partials directory. + +Partials are especially important for themes as it gives users an opportunity +to overwrite just a small part of your theme, while maintaining future compatibility. + +Theme developers may want to include a few partials with empty HTML +files in the theme just so end users have an easy place to inject their +customized content. + +I've found it helpful to include a header and footer template in +partials so I can include those in all the full page layouts. 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/ + ▾ partials/ + header.html + footer.html + +By ensuring that we only reference [variables](/layout/variables/) +used for both nodes and pages, we can use the same partials for both. + +## Partial vs Template + +Version v0.12 of Hugo introduced the `partial` call inside the template system. +This is a change to the way partials were handled previously inside the +template system. In earlier versions, Hugo didn’t treat partials specially, and +you could include a partial template with the `template` call in the standard +template language. + +With the addition of the theme system in v0.11, it became apparent that a theme +& override aware partial was needed. + +When using Hugo v0.12 and above, please use the `partial` call (and leave out +the “partial/” path). The old approach would still work, but wouldn’t benefit from +the ability to have users override the partial theme file with local layouts. + +## Example header.html +This header template is used for [spf13.com](http://spf13.com): + + + + + + + {{ partial "meta.html" . }} + + + {{ .Title }} : spf13.com + + {{ if .RSSlink }}{{ end }} + + {{ partial "head_includes.html" . }} + + + +## Example footer.html +This footer template is used for [spf13.com](http://spf13.com): + + + + + + +**For examples of referencing these templates, see [single content +templates](/templates/content), [list templates](/templates/list) and [homepage templates](/templates/homepage).** -- cgit v1.3