ef02e34eCorrect the mmark example frontmatter parameter6e91e900SectionPagesMenu > sectionPagesMenu1a0db1a6Adjust sectionPagesMenuf9f87d9dFix extension's missing period.7062ae07Remove Press and Articles page771f2b38Remove outdated and redudant content file for release notes64cf47c3Remove outdated note in docs contribution guidebdb11b89Fix typo8324af70Fixes broken link on Roadmapd93f0992functions: Add all missing binary comparison operatorsfb7ae80aFix typo in usage.mdfbdae08bFix typo in content-management/taxonomies.md66fab8d2Make <title> less stutteryb3cd4c22Remove old temp release notes5589ba96Fix typos in templates/lists.mdaf3a0807http > HTTPb2af90aeRemove formatting in description of blog article6e2e60a9Add blog article about Netlify files0bb6f2f2Use title in archetype file7b2490ffGet the Archetypes up to new specf401d69bLoad CSS and JS via HTTP/2 server push4aef4944Adjust titles362acdb2Fix typo in quickstartc2440560Remove inline icons from installation guided2edcbc3Revert "Fix links to Disqus template documentation"622f49cfAdd a full commands section at the quick start end752f065bFix server command in README93e08e19Fix links to Disqus template documentation5e0cfaa9Adjust Linux installd51397c2Fix broken link in Quick Start1fb39846Add /quickstart alias to quickstart7440616bAdd new and simpler quickstartb3ec6986Let page title correspond to function name replaceREb44499c9Add YouTube tutorial about taxonomies88b9eb0eAdd RSS templates example6c0bde3fUpdate slice.md6c212ea6Reorder to match the following content orderd2122992Complete "content" spelling under theme componentse4824eb3Fix the output shortcode and its usage0adfc945Add archetypes YouTube video638e9d9bFix double "your" typo in taxonomies.md git-subtree-dir: docs git-subtree-split:ef02e34eaf
2.4 KiB
title, description, qref, godocref, date, publishdate, lastmod, categories, menu, toc, signature, workson, hugoversion, relatedfuncs, deprecated, draft, aliases, needsexamples
| title | description | qref | godocref | date | publishdate | lastmod | categories | menu | toc | signature | workson | hugoversion | relatedfuncs | deprecated | draft | aliases | needsexamples | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| default | Allows setting a default value that can be returned if a first value is not set. | Returns a default value if a value is not set when checked. | 2017-02-01 | 2017-02-01 | 2017-02-01 |
|
|
|
false | false |
|
false |
default checks whether a given value is set and returns a default value if it is not. Set in this context means different things depending on date type:
- non-zero for numeric types and times
- non-zero length for strings, arrays, slices, and maps
- any boolean or struct value
- non-nil for any other types
default function examples reference the following content page:
{{< code file="content/posts/default-function-example.md" >}}
title: Sane Defaults seo_title: date: 2017-02-18 font: oldparam: The default function helps make your templating DRYer. newparam:
{{< /code >}}
default can be written in more than one way:
{{ index .Params "font" | default "Roboto" }}
{{ default "Roboto" (index .Params "font") }}
Both of the above default function calls return Roboto.
A default value, however, does not need to be hard coded like the previous example. The default value can be a variable or pulled directly from the front matter using dot notation:
{{< code file="variable-as-default-value.html" nocopy="true" >}} {{$old := .Params.oldparam }}
{{ .Params.newparam | default $old }}
{{< /code >}}Which would return:
<p>The default function helps make your templating DRYer.</p>
And then using dot notation
{{< code file="dot-notation-default-value.html" >}}
{{< /code >}}Which would return
{{< output file="dot-notation-default-return-value.html" >}}
{{< /output >}}The following have equivalent return values but are far less terse. This demonstrates the utility of default:
Using if:
{{< code file="if-instead-of-default.html" nocopy="true" >}}
=> Sane Defaults {{< /code >}}Using with:
{{< code file="with-instead-of-default.html" nocopy="true" >}}
=> Sane Defaults {{< /code >}}