hugo

Fork of github.com/gohugoio/hugo with reverse pagination support

git clone git://git.shimmy1996.com/hugo.git

site.md (4932B)

    1 ---
    2 title: Site Variables
    3 linktitle: Site Variables
    4 description: Many, but not all, site-wide variables are defined in your site's configuration. However, Hugo provides a number of built-in variables for convenient access to global values in your templates.
    5 date: 2017-02-01
    6 publishdate: 2017-02-01
    7 lastmod: 2017-02-01
    8 categories: [variables and params]
    9 keywords: [global,site]
   10 draft: false
   11 menu:
   12   docs:
   13     parent: "variables"
   14     weight: 10
   15 weight: 10
   16 sections_weight: 10
   17 aliases: [/variables/site-variables/]
   18 toc: true
   19 ---
   20 
   21 The following is a list of site-level (aka "global") variables. Many of these variables are defined in your site's [configuration file][config], whereas others are built into Hugo's core for convenient usage in your templates.
   22 
   23 ## Get the Site object from a partial
   24 
   25 All the methods below, e.g. `.Site.RegularPages` can also be reached via the global [`site`](/functions/site/) function, e.g. `site.RegularPages`, which can be handy in partials where the `Page` object isn't easily available. {{< new-in "0.53" >}}.
   26 
   27 ## Site Variables List
   28 
   29 .Site.AllPages
   30 : array of all pages, regardless of their translation.
   31 
   32 .Site.Author
   33 : a map of the authors as defined in the site configuration.
   34 
   35 .Site.BaseURL
   36 : the base URL for the site as defined in the site configuration.
   37 
   38 .Site.BuildDrafts
   39 : a boolean (default: `false`) to indicate whether to build drafts as defined in the site configuration.
   40 
   41 .Site.Copyright
   42 : a string representing the copyright of your website as defined in the site configuration.
   43 
   44 .Site.Data
   45 : custom data, see [Data Templates](/templates/data-templates/).
   46 
   47 .Site.DisqusShortname
   48 : a string representing the shortname of the Disqus shortcode as defined in the site configuration.
   49 
   50 .Site.GoogleAnalytics
   51 : a string representing your tracking code for Google Analytics as defined in the site configuration.
   52 
   53 .Site.Home
   54 : reference to the homepage's [page object](https://gohugo.io/variables/page/)
   55 
   56 .Site.IsMultiLingual
   57 : whether there are more than one language in this site. See [Multilingual](/content-management/multilingual/) for more information.
   58 
   59 .Site.IsServer
   60 : a boolean to indicate if the site is being served with Hugo's built-in server. See [`hugo server`](/commands/hugo_server/) for more information.
   61 
   62 .Site.Language.Lang
   63 : the language code of the current locale (e.g., `en`).
   64 
   65 .Site.Language.LanguageName
   66 : the full language name (e.g. `English`).
   67 
   68 .Site.Language.Weight
   69 : the weight that defines the order in the `.Site.Languages` list.
   70 
   71 .Site.Language
   72 : indicates the language currently being used to render the website. This object's attributes are set in site configurations' language definition.
   73 
   74 .Site.LanguageCode
   75 : a string representing the language tag as defined in the site configuration.
   76 
   77 .Site.LanguagePrefix
   78 : this can be used to prefix URLs to point to the correct language. It will even work when only one defined language. See also the functions [absLangURL](/functions/abslangurl/) and [relLangURL](/functions/rellangurl).
   79 
   80 .Site.Languages
   81 : an ordered list (ordered by defined weight) of languages.
   82 
   83 .Site.LastChange
   84 : a string representing the date/time of the most recent change to your site. This string is based on the [`date` variable in the front matter](/content-management/front-matter) of your content pages.
   85 
   86 .Site.Menus
   87 : all of the menus in the site.
   88 
   89 .Site.Pages
   90 : array of all content ordered by Date with the newest first. This array contains only the pages in the current language. See [`.Site.Pages`](#site-pages).
   91 
   92 .Site.RegularPages
   93 : a shortcut to the *regular* page collection. `.Site.RegularPages` is equivalent to `where .Site.Pages "Kind" "page"`. See [`.Site.Pages`](#site-pages).
   94 
   95 .Site.Sections
   96 : top-level directories of the site.
   97 
   98 .Site.Taxonomies
   99 : the [taxonomies](/taxonomies/usage/) for the entire site. Also see section [Use `.Site.Taxonomies` Outside of Taxonomy Templates](/variables/taxonomy/#use-sitetaxonomies-outside-of-taxonomy-templates).
  100 
  101 .Site.Title
  102 : a string representing the title of the site.
  103 
  104 ## The `.Site.Params` Variable
  105 
  106 `.Site.Params` is a container holding the values from the `params` section of your site configuration.
  107 
  108 ### Example: `.Site.Params`
  109 
  110 The following `config.[yaml|toml|json]` defines a site-wide param for `description`:
  111 
  112 {{< code-toggle file="config" >}}
  113 baseURL = "https://yoursite.example.com/"
  114 
  115 [params]
  116   description = "Tesla's Awesome Hugo Site"
  117   author = "Nikola Tesla"
  118 {{</ code-toggle >}}
  119 
  120 You can use `.Site.Params` in a [partial template](/templates/partials/) to call the default site description:
  121 
  122 {{< code file="layouts/partials/head.html" >}}
  123 <meta name="description" content="{{if .IsHome}}{{ $.Site.Params.description }}{{else}}{{.Description}}{{end}}" />
  124 {{< /code >}}
  125 
  126 ## The `.Site.Pages` Variable {#site-pages}
  127 
  128 ### `.Site.Pages` compared to `.Pages`
  129 
  130 {{< getcontent path="readfiles/pages-vs-site-pages.md" >}}
  131 
  132 
  133 
  134 
  135 [config]: /getting-started/configuration/