# Correct format to print a variable inside a partial template?

**URL:** <https://discourse.gohugo.io/t/correct-format-to-print-a-variable-inside-a-partial-template/50072>\
**Category:** support\
**Created:** [May 29, 2024, 11:00pm UTC](https://discourse.gohugo.io/t/correct-format-to-print-a-variable-inside-a-partial-template/50072 "2024-05-29T23:00:33Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Floren](https://avatars.discourse-cdn.com/v4/letter/f/51bf81/32.png) [@Floren](https://discourse.gohugo.io/u/Floren)\
**Post date:** [May 29, 2024, 11:00pm UTC](https://discourse.gohugo.io/t/correct-format-to-print-a-variable-inside-a-partial-template/50072/1 "2024-05-29T23:00:33Z")

</div>

I’m trying to print the output of a variable inside [this template](https://github.com/axivo/hugo-module/blob/main/global/layouts/partials/navbar.html):

```auto
{{- $menu := .Site.Params.sectionPagesMenu | default "main" -}}

```

I’m not sure what is the correct format to do that. Thank you for your suggestions.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [May 29, 2024, 11:28pm UTC](https://discourse.gohugo.io/t/correct-format-to-print-a-variable-inside-a-partial-template/50072/2 "2024-05-29T23:28:33Z")

</div>

> [@Floren](#):
>
> trying to print the output of a variable

I don’t know what that means.

```plaintext
{{ myVariable := 42 }}
{{ $myVariable }} --> prints "42"

```

---

<div class="post-metadata">

**Author:** ![Floren](https://avatars.discourse-cdn.com/v4/letter/f/51bf81/32.png) [@Floren](https://discourse.gohugo.io/u/Floren)\
**Post date:** [May 29, 2024, 11:41pm UTC](https://discourse.gohugo.io/t/correct-format-to-print-a-variable-inside-a-partial-template/50072/3 "2024-05-29T23:41:04Z")

</div>

I tried the approach you suggest, but it outputs nothing. Is there a way to enable debug mode into all templates to display all variables while running the `hugo server`?

Or another way that I could accomplish my validation, how do I print all `.Site` variables through browser console? I added the following lines into header but the output is minimalist:

```auto
  var hugoLog = JSON.parse({{ jsonify . }});
  console.log('Hugo Debug: ', hugoLog);

```

![image](https://canada1.discourse-cdn.com/flex036/uploads/gohugo/original/3X/3/b/3b37ed6bc4d317c4b0b8c513b3a75df5c75383c7.png)

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [May 29, 2024, 11:44pm UTC](https://discourse.gohugo.io/t/correct-format-to-print-a-variable-inside-a-partial-template/50072/4 "2024-05-29T23:44:00Z")

</div>

> [@Floren](#):
>
> debug mode into all templates to display all variables

No

> [@Floren](#):
>
> it outputs nothing

Does it ouput nothing or display nothing?

```plaintext
{{ $myVariable | warnf "%v" }}

```

---

<div class="post-metadata">

**Author:** ![irkode](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/irkode/32/26135_2.png) [@irkode](https://discourse.gohugo.io/u/irkode)\
**Post date:** [May 30, 2024, 8:01am UTC](https://discourse.gohugo.io/t/correct-format-to-print-a-variable-inside-a-partial-template/50072/5 "2024-05-30T08:01:20Z")

</div>

> [@Floren](#):
>
> `var hugoLog = JSON.parse({{ jsonify . }});`

This one is the current context so _Page_. From your screenshot. Use site or .Site instead.

---

<div class="post-metadata">

**Author:** ![Floren](https://avatars.discourse-cdn.com/v4/letter/f/51bf81/32.png) [@Floren](https://discourse.gohugo.io/u/Floren)\
**Post date:** [May 30, 2024, 2:07pm UTC](https://discourse.gohugo.io/t/correct-format-to-print-a-variable-inside-a-partial-template/50072/6 "2024-05-30T14:07:52Z")

</div>

@irkode just to make sure I understand, I should have:

```auto
var hugoLog = JSON.parse({{ jsonify .Site }});

```

Is that correct?

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [May 30, 2024, 2:23pm UTC](https://discourse.gohugo.io/t/correct-format-to-print-a-variable-inside-a-partial-template/50072/7 "2024-05-30T14:23:21Z")

</div>

> [@Floren](#):
>
> Is that correct?

That won’t work, and there’s no way to do what you want to do, with either `Page` or `Site` objects.

This only returns a subset… it’s incomplete:

```plaintext
<pre>{{ jsonify (dict "indent" " ") .Page }}</pre>

```

These return nothing because (internally) the `Site` object is wrapped:

```plaintext
<pre>{{ jsonify (dict "indent" " ") .Site }}</pre>
<pre>{{ jsonify (dict "indent" " ") site }}</pre>

```

Going back to your original question…

> [@Floren](#):
>
> Is there a way to enable debug mode into all templates to display all variables while running the `hugo server`?

The answer is still no.

---

<div class="post-metadata">

**Author:** ![Floren](https://avatars.discourse-cdn.com/v4/letter/f/51bf81/32.png) [@Floren](https://discourse.gohugo.io/u/Floren)\
**Post date:** [May 30, 2024, 2:29pm UTC](https://discourse.gohugo.io/t/correct-format-to-print-a-variable-inside-a-partial-template/50072/8 "2024-05-30T14:29:40Z")

</div>

Thank you @jmooring. So there is no way for me to have a list of all .Site variables, on each page. I’m wondering how developers debug the .Site variables.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [May 30, 2024, 2:35pm UTC](https://discourse.gohugo.io/t/correct-format-to-print-a-variable-inside-a-partial-template/50072/9 "2024-05-30T14:35:01Z")

</div>

> [@Floren](#):
>
> I’m wondering how developers debug the .Site variables.

Debug what? These values are immutable.

---

<div class="post-metadata">

**Author:** ![Floren](https://avatars.discourse-cdn.com/v4/letter/f/51bf81/32.png) [@Floren](https://discourse.gohugo.io/u/Floren)\
**Post date:** [May 30, 2024, 2:42pm UTC](https://discourse.gohugo.io/t/correct-format-to-print-a-variable-inside-a-partial-template/50072/10 "2024-05-30T14:42:09Z")

</div>

@jmooring I’m simply trying to display on each page what are the .Site values present, as I have several modules with each having additional settings.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [May 30, 2024, 2:45pm UTC](https://discourse.gohugo.io/t/correct-format-to-print-a-variable-inside-a-partial-template/50072/11 "2024-05-30T14:45:12Z")

</div>

If you’re talking about site parameters, inspect `.Site.Parameters`.

If you’re talking about configuration settings, most aren’t exposed to the templates anyway.

If you’re intent of having a complete map of exposed settings you’ll need to build the map yourself.

---

<div class="post-metadata">

**Author:** ![Floren](https://avatars.discourse-cdn.com/v4/letter/f/51bf81/32.png) [@Floren](https://discourse.gohugo.io/u/Floren)\
**Post date:** [May 30, 2024, 2:49pm UTC](https://discourse.gohugo.io/t/correct-format-to-print-a-variable-inside-a-partial-template/50072/12 "2024-05-30T14:49:28Z")

</div>

Thank you @jmooring. I’m wondering if there is a tutorial for this, I’ve been searching for a solution but could not find anything.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [May 30, 2024, 2:50pm UTC](https://discourse.gohugo.io/t/correct-format-to-print-a-variable-inside-a-partial-template/50072/13 "2024-05-30T14:50:22Z")

</div>

> [@Floren](#):
>
> I’m wondering if there is a tutorial for this,

For what?

---

<div class="post-metadata">

**Author:** ![Floren](https://avatars.discourse-cdn.com/v4/letter/f/51bf81/32.png) [@Floren](https://discourse.gohugo.io/u/Floren)\
**Post date:** [May 30, 2024, 2:55pm UTC](https://discourse.gohugo.io/t/correct-format-to-print-a-variable-inside-a-partial-template/50072/14 "2024-05-30T14:55:51Z")

</div>

> [@jmooring](#):
>
> If you’re intent of having a complete map of exposed settings you’ll need to build the map yourself.

For that.

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [May 30, 2024, 2:58pm UTC](https://discourse.gohugo.io/t/correct-format-to-print-a-variable-inside-a-partial-template/50072/15 "2024-05-30T14:58:00Z")

</div>

```plaintext
  {{ $siteMap := dict
    "BaseURL" .Site.BaseURL
    "BuildDrafts" .Site.BuildDrafts
    .etc.
  }}

```

---

<div class="post-metadata">

**Author:** ![jmooring](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/jmooring/32/4214_2.png) [@jmooring](https://discourse.gohugo.io/u/jmooring)\
**Post date:** [May 30, 2024, 4:30pm UTC](https://discourse.gohugo.io/t/correct-format-to-print-a-variable-inside-a-partial-template/50072/16 "2024-05-30T16:30:07Z")

</div>

A post was split to a new topic: [Select menus based on directory structure](https://discourse.gohugo.io/t/select-menus-based-on-directory-structure/50084)

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [June 1, 2024, 4:30pm UTC](https://discourse.gohugo.io/t/correct-format-to-print-a-variable-inside-a-partial-template/50072/17 "2024-06-01T16:30:25Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
