Skip to main content Svelte Highlight v7.21.1

Go template language preview

1. Greeting template

a define block, a conditional, and a range loop
horizon-dark
{{- /* render a greeting */ -}}
{{ define "greeting" }}
Hello, {{ .Name | printf "%s" }}!
{{ if .Admin }}
  You are an admin, {{ $name := .Name }}{{ $name }}.
{{ else }}
  {{ range .Items }}
    - {{ . }}
  {{ end }}
{{ end }}
{{ end }}
atom-one-dark
{{- /* render a greeting */ -}}
{{ define "greeting" }}
Hello, {{ .Name | printf "%s" }}!
{{ if .Admin }}
  You are an admin, {{ $name := .Name }}{{ $name }}.
{{ else }}
  {{ range .Items }}
    - {{ . }}
  {{ end }}
{{ end }}
{{ end }}
github-dark
{{- /* render a greeting */ -}}
{{ define "greeting" }}
Hello, {{ .Name | printf "%s" }}!
{{ if .Admin }}
  You are an admin, {{ $name := .Name }}{{ $name }}.
{{ else }}
  {{ range .Items }}
    - {{ . }}
  {{ end }}
{{ end }}
{{ end }}
dracula
{{- /* render a greeting */ -}}
{{ define "greeting" }}
Hello, {{ .Name | printf "%s" }}!
{{ if .Admin }}
  You are an admin, {{ $name := .Name }}{{ $name }}.
{{ else }}
  {{ range .Items }}
    - {{ . }}
  {{ end }}
{{ end }}
{{ end }}
nord
{{- /* render a greeting */ -}}
{{ define "greeting" }}
Hello, {{ .Name | printf "%s" }}!
{{ if .Admin }}
  You are an admin, {{ $name := .Name }}{{ $name }}.
{{ else }}
  {{ range .Items }}
    - {{ . }}
  {{ end }}
{{ end }}
{{ end }}
github
{{- /* render a greeting */ -}}
{{ define "greeting" }}
Hello, {{ .Name | printf "%s" }}!
{{ if .Admin }}
  You are an admin, {{ $name := .Name }}{{ $name }}.
{{ else }}
  {{ range .Items }}
    - {{ . }}
  {{ end }}
{{ end }}
{{ end }}

2. Comparisons and built-ins

eq, len, and the pipe operator
horizon-dark
{{ if eq .Status "active" }}
  {{ len .Items }} items
{{ end }}
{{ .Description | html }}
atom-one-dark
{{ if eq .Status "active" }}
  {{ len .Items }} items
{{ end }}
{{ .Description | html }}
github-dark
{{ if eq .Status "active" }}
  {{ len .Items }} items
{{ end }}
{{ .Description | html }}
dracula
{{ if eq .Status "active" }}
  {{ len .Items }} items
{{ end }}
{{ .Description | html }}
nord
{{ if eq .Status "active" }}
  {{ len .Items }} items
{{ end }}
{{ .Description | html }}
github
{{ if eq .Status "active" }}
  {{ len .Items }} items
{{ end }}
{{ .Description | html }}

3. Blocks and templates

block and template actions
horizon-dark
{{ block "content" . }}
  default content
{{ end }}
{{ template "footer" . }}
atom-one-dark
{{ block "content" . }}
  default content
{{ end }}
{{ template "footer" . }}
github-dark
{{ block "content" . }}
  default content
{{ end }}
{{ template "footer" . }}
dracula
{{ block "content" . }}
  default content
{{ end }}
{{ template "footer" . }}
nord
{{ block "content" . }}
  default content
{{ end }}
{{ template "footer" . }}
github
{{ block "content" . }}
  default content
{{ end }}
{{ template "footer" . }}