A variable is accessed by referencing the variable name.
nfiguration (for sitewide values), or through the meta
data of each specific piece of content. You can define any values of any
type (supported by your front matter/config format) and use them however
you want to inside of your templates.
California Suburban Home Scale 1:160
A unique characteristic of go templates is they are content aware. Variables and
content will be sanitized depending on the context of where they are used. More
details can be found in the go docs.
Go template ship with a few functions which provide basic functionality. The go
template system also provides a mechanism for applications to extend the
available functions with their own. Hugo template
functions provide some additional functionality we believe
are useful for building websites. Functions are called by using their name
followed by the required parameters separated by spaces. Template
functions cannot be added without recompiling hugo.
Example:
params:
CopyrightHTML: "Copyright © 2013 John Doe. All Rights Reserved."TwitterUser: "spf13"SidebarRecentLimit: 5
Within a footer layout, you might then declare a <footer> which is only
provided if the CopyrightHTML parameter is provided, and if it is given,
you would declare it to be HTML-safe, so that the HTML entity is not escaped
again. This would let you easily update just your top-level config file each
January 1st, instead of hunting through your templates.
An alternative way of writing the “if” and then referencing the same value
is to use “with” instead. With rebinds the context . within its scope,
and skips the block if the variable is absent: