Using Site Configuration Data in Your Theme

Your layouts use {{ .Site.Title }} to display the name of the site in the browser title bar and in your header navigation. You can place all kinds of other data in your site’s configuration file and use it as well.

For example, let’s use the site’s configuration to build additional <meta> tags in the site’s header. The site configuration file has built-in fields like Title, but you can add anything you’d like to this file if you add it to a params section of the file.

Open config.toml and add a new params section that defines the author of the site and a description of the site:

 [params]
  author = ​"Brian Hogan"
  description = ​"My portfolio site"

Then, open the file themes/basic/layouts/partials/head.html and add a new author meta tag to the page:

»<meta name=​"author"​ content=​"{{ .Site.Params.author }}"​>
 <link rel=​"stylesheet"​ href=​"{{ "​css​/​style​.​css​"​ ​|​ relURL ​}}"​>

Below that, add one for the description:

 <meta name=​"description"​ content=​"{{ .Site.Params.description }}"​>

Now all of your pages will have these tags filled in. If you open your page in a browser and look at its source, you’ll see the data:

 ...
  <title>Brian&#39;s Portfolio</title>
» <meta name=​"author"​ content=​"Brian Hogan"​>
» <meta name=​"description"​ content=​"My portfolio site"​>
  <link rel=​"stylesheet"​ href=​"/css/style.css"​>
 ...

The description field isn’t page-specific yet, but you’ll fix that shortly after you explore how to use front matter data to pull in content.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.143.31