dict_has_key
The dict_has_key function checks whether a dictionary contains a specific key.
Syntax
{{ dict_has_key dictionary "key" }}
Example
{{ $data := dict_create "title" "Hello World" "author" "Alice" }}
{{ if dict_has_key $data "title" }}
<h1>{{ dict_get $data "title" }}</h1>
{{ end }}
{{ if dict_has_key $data "subtitle" }}
<h2>{{ dict_get $data "subtitle" }}</h2>
{{ else }}
<h2>No subtitle</h2>
{{ end }}
Output:
<h1>Hello World</h1>
<h2>No subtitle</h2>
Notes
- Returns
trueif the key exists,falseotherwise - Useful for conditional rendering based on data availability
- The key's value doesn't matter—even empty string or
falsevalues returntrueif the key exists