mirror of
https://github.com/gohugoio/hugo.git
synced 2026-08-24 23:38:53 +00:00
1.1 KiB
1.1 KiB
title, linktitle, description, godocref, date, publishdate, lastmod, categories, tags, ns, signature, workson, hugoversion, relatedfuncs, deprecated
| title | linktitle | description | godocref | date | publishdate | lastmod | categories | tags | ns | signature | workson | hugoversion | relatedfuncs | deprecated | ||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| with | 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 |
|
|
|
false |
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.
The following example checks for a user-defined site variable defined as twitteruser in your site configuration. If the key-value is not set, the following will render nothing:
{{% code file="layouts/partials/twitter.html" %}}
{{with .Site.Params.twitteruser}}<span class="twitter">
<a href="https://twitter.com/{{.}}" rel="author">
<img src="/images/twitter.png" width="48" height="48" title="Twitter: {{.}}"
alt="Twitter"></a>
</span>{{end}}
{{% /code %}}