Using Hugo Variables with Alpine
Not only using Hugo’s variables with Go template language, but also Alpine’s directive.
失くすものさえない今が強くなるチャンスよ
Not only using Hugo’s variables with Go template language, but also Alpine’s directive.
Minimizing HTML is provided by Hugo. We can minimize HTML under production.
TailwindCSS is great for JAMstack, but we have to integrate TailwindCSS with Hugo manually.
The Go Templates make heavy use of range
to iterate over a Map, Array, or Slice.
We can use range
to iterate over an array to render HTML.
For site-level custom data, we can store them on the params
section of config.json
.
We can define site variables in config.json
and access them by Go template language.
We can use .Content
page variable to access Markdown content.
We can use relref
to get the relative permalink to a page for the href
attribute of <a>
.
We can use ref
to get the absolute permalink to a page for the href
attribute of <a>
.
We can use the |
operator to compose multiple functions for Function Pipeline.
If we use Markdown to define a variable, we can use markdownify
to transform Markdown to HTML.
Hugo provides humanize
function to make a String with the first letter capitalized.
We can use with
to change the context and .
as the context variable.
For user-defined variable, we can either define it as site variable or page variable. $.Param
reads page variable first. If it doesn’t exist, then read site variable.
We can use default
to provide the default value of the template variable instead of using if else
.
We can use :=
to declare a template variable and =
to re-assign it.
We can use if else
for truthy/falsy value in Go template language.