hugo/content/functions/with.md
Bjørn Erik Pedersen ec4e6f9df2 Squashed 'docs/' content from commit f887bd7b
git-subtree-dir: docs
git-subtree-split: f887bd7b4e3e7c7e76cd63951e5b0d37d8fe0ac7
2017-08-10 17:18:22 +02:00

1 KiB

title description godocref date publishdate lastmod categories menu signature workson hugoversion relatedfuncs deprecated
with Rebinds the context (`.`) within its scope and skips the block if the variable is absent. 2017-02-01 2017-02-01 2017-03-12
functions
fundamentals
docs
parent
functions
with INPUT
false

An alternative way of writing an if statement 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 or unset.

The following example checks for a user-defined site variable called twitteruser. If the key-value is not set, the following will render nothing:

{{< code file="layouts/partials/twitter.html" >}} {{with .Site.Params.twitteruser}} Twitter {{end}} {{< /code >}}