hugo/content/en/templates/internal.md
Bjørn Erik Pedersen 07b8d9466d Squashed 'docs/' changes from 9cece6640..fb551cc75
fb551cc75 Update index.md
7af894857 Update index.md
d235753ea Hugo 0.82.1
e03e72deb Merge branch 'temp0821'
e62648961 Merge branch 'release-0.82.1'
e1ab0f6eb releaser: Add release notes to /docs for release of 0.82.1
5d354c38d Replaced ``` code blocks with Code Toggler
c9d065c20 Remove duplicate YAML keys (#1420)
8ae31e701 Add webp image encoding support
848f2af26 Update internal.md (#1407)
c103a86a4 Fix `ref` shortcode example output (#1409)
9f8ba56dc Remove leading dot from where function KEY (#1419)
363251a51 Improve presentation of template lookup order (#1382)
b73da986d Improve description of Page Resources (#1381)
4e0bb96d5 Rework robots.txt page (#1405)
edf893e6f Update migrations.md (#1412)
450f1580b Add link to `site` function doc (#1417)
cfffa6e6f Added one extension to the list (#1414)
05f1665a0 Update theme
5de0b1c6a Update theme
250e20552 Add hugo.IsExtended
dea5e1fd7 Fix typo on merge function page (#1408)
1bbed2cf3 Update configuration.md
be0b64a46 Omit ISO
cbb5b8367 Fix `dateFormat` documentation
698f15466 Regenerate the docshelper
f9a8a7cb6 Update multilingual.md
a22dc6267 Fix grammar (#1398)
eb98b0997 Fix pretty URL example (#1397)
f4c4153dc Mention date var complementation in post scheduling (#1396)
17fae284c Fix resources.ExecuteAsTemplate argument order (#1394)
97e2c2abb Use code-toggle shortcode in `multilingual.md` (#1388)
3a84929bb Harmonize capitalization (#1393)
17f15daa6 fix file naming used in example (#1392)
5d97b6a18 Add slice syntax to sections permalinks config
00665b97b Improve description of `site.md`
edcf5e3fc Fix example in `merge.md`
f275ab778 Update postprocess.md
9593e3991 Fix file name
59bd9656f Update postprocess.md
1172fb6d0 Update to theNewDynamic repository (#1263)
f5b5c1d2c Update Hugo container image
4f2e92f2a Adapt anchorize.md to Goldmark
98aa19073 Directly link to `highlight` shortcode (#1384)
4c75c2422 Fix header level
f15c06f23 markdownify: add note about render-hooks and .RenderString (#1281)
69c82eb68 Remove Blackfriday reference from shortcode desc (#1380)
36de478df Update description of ignoreFiles config setting (#1377)
6337699d8 Remove "Authors" page from documentation (#1371)
35e73ca90 fix indent in example (#1372)
d3f01f19a Remove opening body tag from header example (#1376)
341a5a7d8 Update index.md
c9bfdbee6 Release 0.82.0
119644949 releaser: Add release notes to /docs for release of 0.82.0
32efaed78 docs: Regenerate docs helper
dea5449a2 docs: Regen CLI docs
eeab18fce Merge commit '81689af79901f0cdaff765cda6322dd4a9a7ccb3'
d508a1259 Attributes for code fences should be placed after the lang indicator only
c80905cef deps: Update to esbuild v0.9.0
95350eb79 Add support for Google Analytics v4
02d36f9bc Allow markdown attribute lists to be used in title render hooks
7df220a64 Merge commit '9d31f650da964a52f05fc27b7fb99cf3e09778cf'
d80bf61b7 Fixes #7698.

git-subtree-dir: docs
git-subtree-split: fb551cc750faa83a1493b0e0d0898cd98ab74465
2021-04-20 20:21:45 +02:00

7.7 KiB

title linktitle description date publishdate lastmod categories keywords menu weight sections_weight draft aliases toc wip
Internal Templates Internal Templates Hugo ships with a group of boilerplate templates that cover the most common use cases for static websites. 2017-03-06 2017-03-06 2017-03-06
templates
internal
analytics
docs
parent weight
templates 168
168 168 false
true true

{{% warning %}} While the following internal templates are called similar to partials, they do not observe the partial template lookup order. {{% /warning %}}

Google Analytics

Hugo ships with internal templates for Google Analytics tracking, including both synchronous and asynchronous tracking codes. As well as support for both v3 and v4 of Google Analytics.

Configure Google Analytics

Provide your tracking id in your configuration file:

Google Analytics v3 (analytics.js) {{< code-toggle file="config" >}} googleAnalytics = "UA-PROPERTY_ID" {{</ code-toggle >}}

Google Analytics v4 (gtag.js) {{< code-toggle file="config" >}} googleAnalytics = "G-MEASUREMENT_ID" {{</ code-toggle >}}

Use the Google Analytics Template

You can then include the Google Analytics internal template:

{{ template "_internal/google_analytics.html" . }}
{{ template "_internal/google_analytics_async.html" . }}

When using Google Analytics v4 use _internal/google_analytics.html.

A .Site.GoogleAnalytics variable is also exposed from the config.

Disqus

Hugo also ships with an internal template for Disqus comments, a popular commenting system for both static and dynamic websites. In order to effectively use Disqus, you will need to secure a Disqus "shortname" by signing up for the free service.

Configure Disqus

To use Hugo's Disqus template, you first need to set a single configuration value:

{{< code-toggle file="config" >}} disqusShortname = "yourdiscussshortname" {{</ code-toggle >}}

You also have the option to set the following in the front matter for a given piece of content:

  • disqus_identifier
  • disqus_title
  • disqus_url

Use the Disqus Template

To add Disqus, include the following line in templates where you want your comments to appear:

{{ template "_internal/disqus.html" . }}

A .Site.DisqusShortname variable is also exposed from the config.

Conditional Loading of Disqus Comments

Users have noticed that enabling Disqus comments when running the Hugo web server on localhost (i.e. via hugo server) causes the creation of unwanted discussions on the associated Disqus account.

You can create the following layouts/partials/disqus.html:

{{< code file="layouts/partials/disqus.html" download="disqus.html" >}}

comments powered by Disqus {{< /code >}}

The if statement skips the initialization of the Disqus comment injection when you are running on localhost.

You can then render your custom Disqus partial template as follows:

{{ partial "disqus.html" . }}

Open Graph

An internal template for the Open Graph protocol, metadata that enables a page to become a rich object in a social graph. This format is used for Facebook and some other sites.

Configure Open Graph

Hugo's Open Graph template is configured using a mix of configuration variables and front-matter on individual pages.

{{< code-toggle file="config" >}} [params] title = "My cool site" images = ["site-feature-image.jpg"] description = "Text about my cool site" [taxonomies] series = "series" {{</ code-toggle >}}

{{< code-toggle file="content/blog/my-post" >}} title = "Post title" description = "Text about this post" date = "2006-01-02" images = ["post-cover.png"] audio = [] videos = [] series = [] tags = [] {{</ code-toggle >}}

Hugo uses the page title and description for the title and description metadata. The first 6 URLs from the images array are used for image metadata. If page bundles are used and the images array is empty or undefined, images with filenames matching *feature* or *cover*,*thumbnail* are used for image metadata.

Various optional metadata can also be set:

  • Date, published date, and last modified data are used to set the published time metadata if specified.
  • audio and videos are URL arrays like images for the audio and video metadata tags, respectively.
  • The first 6 tags on the page are used for the tags metadata.
  • The series taxonomy is used to specify related "see also" pages by placing them in the same series.

If using YouTube this will produce a og:video tag like <meta property="og:video" content="url">. Use the https://youtu.be/<id> format with YouTube videos (example: https://youtu.be/qtIqKaDlqXo).

Use the Open Graph Template

To add Open Graph metadata, include the following line between the <head> tags in your templates:

{{ template "_internal/opengraph.html" . }}

Twitter Cards

An internal template for Twitter Cards, metadata used to attach rich media to Tweets linking to your site.

Configure Twitter Cards

Hugo's Twitter Card template is configured using a mix of configuration variables and front-matter on individual pages.

{{< code-toggle file="config" >}} [params] images = ["site-feature-image.jpg"] description = "Text about my cool site" {{</ code-toggle >}}

{{< code-toggle file="content/blog/my-post" >}} title = "Post title" description = "Text about this post" images = ["post-cover.png"] {{</ code-toggle >}}

If images aren't specified in the page front-matter, then hugo searches for image page resources with feature, cover, or thumbnail in their name. If no image resources with those names are found, the images defined in the site config are used instead. If no images are found at all, then an image-less Twitter summary card is used instead of summary_large_image.

Hugo uses the page title and description for the card's title and description fields. The page summary is used if no description is given.

Use the Twitter Cards Template

To add Twitter card metadata, include the following line between the <head> tags in your templates:

{{ template "_internal/twitter_cards.html" . }}

The Internal Templates

  • _internal/disqus.html
  • _internal/google_news.html
  • _internal/google_analytics.html
  • _internal/google_analytics_async.html
  • _internal/opengraph.html
  • _internal/pagination.html
  • _internal/schema.html
  • _internal/twitter_cards.html