github.com/lyeb/hugo@v0.47.1/docs/content/en/templates/template-debugging.md (about)

     1  ---
     2  title: Template Debugging
     3  # linktitle: Template Debugging
     4  description: You can use Go templates' `printf` function to debug your Hugo  templates. These snippets provide a quick and easy visualization of the variables available to you in different contexts.
     5  godocref: http://golang.org/pkg/fmt/
     6  date: 2017-02-01
     7  publishdate: 2017-02-01
     8  lastmod: 2017-02-01
     9  categories: [templates]
    10  keywords: [debugging,troubleshooting]
    11  menu:
    12    docs:
    13      parent: "templates"
    14      weight: 180
    15  weight: 180
    16  sections_weight: 180
    17  draft: false
    18  aliases: []
    19  toc: false
    20  ---
    21  
    22  Here are some snippets you can add to your template to answer some common questions.
    23  
    24  These snippets use the `printf` function available in all Go templates.  This function is an alias to the Go function, [fmt.Printf](http://golang.org/pkg/fmt/).
    25  
    26  ## What Variables are Available in this Context?
    27  
    28  You can use the template syntax, `$.`, to get the top-level template context from anywhere in your template. This will print out all the values under, `.Site`.
    29  
    30  ```
    31  {{ printf "%#v" $.Site }}
    32  ```
    33  
    34  This will print out the value of `.Permalink`:
    35  
    36  
    37  ```
    38  {{ printf "%#v" .Permalink }}
    39  ```
    40  
    41  
    42  This will print out a list of all the variables scoped to the current context
    43  (`.`, aka ["the dot"][tempintro]).
    44  
    45  
    46  ```
    47  {{ printf "%#v" . }}
    48  ```
    49  
    50  
    51  When developing a [homepage][], what does one of the pages you're looping through look like?
    52  
    53  ```
    54  {{ range .Pages }}
    55      {{/* The context, ".", is now each one of the pages as it goes through the loop */}}
    56      {{ printf "%#v" . }}
    57  {{ end }}
    58  ```
    59  
    60  {{% note "`.Pages` on the Homepage" %}}
    61  `.Pages` on the homepage is equivalent to `.Site.RegularPages`.
    62  {{% /note %}}
    63  
    64  ## Why Am I Showing No Defined Variables?
    65  
    66  Check that you are passing variables in the `partial` function:
    67  
    68  ```
    69  {{ partial "header" }}
    70  ```
    71  
    72  This example will render the header partial, but the header partial will not have access to any contextual variables. You need to pass variables explicitly. For example, note the addition of ["the dot"][tempintro].
    73  
    74  ```
    75  {{ partial "header" . }}
    76  ```
    77  
    78  The dot (`.`) is considered fundamental to understanding Hugo templating. For more information, see [Introduction to Hugo Templating][tempintro].
    79  
    80  [homepage]: /templates/homepage/
    81  [tempintro]: /templates/introduction/