# Documentation if and with issues

**URL:** <https://discourse.gohugo.io/t/documentation-if-and-with-issues/35867>\
**Category:** support\
**Created:** [December 2, 2021, 7:14am UTC](https://discourse.gohugo.io/t/documentation-if-and-with-issues/35867 "2021-12-02T07:14:13Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![ddanawoski](https://avatars.discourse-cdn.com/v4/letter/d/edb3f5/32.png) [@ddanawoski](https://discourse.gohugo.io/u/ddanawoski)\
**Post date:** [December 2, 2021, 7:14am UTC](https://discourse.gohugo.io/t/documentation-if-and-with-issues/35867/1 "2021-12-02T07:14:13Z")

</div>

**The with else works** with no issues.  
{{ with .Param “description” }}  
{{ . }}  
{{ else }}  
{{ .Summary }}  
{{ end }}

But the if else doesn’t display the else.  
{{ if (isset .Params “description”) }}  
{{ index .Params “description” }}  
{{ else }}  
{{ .Summary }}  
{{ end }}

> **[Introduction to Hugo Templating](https://gohugo.io/templates/introduction/#example-4-if--else)**
>
> Hugo uses Go's \`html/template\` and \`text/template\` libraries as the basis for the templating.

Kindly help if you have insight into this.

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [December 2, 2021, 7:32am UTC](https://discourse.gohugo.io/t/documentation-if-and-with-issues/35867/2 "2021-12-02T07:32:29Z")

</div>

> [@ddanawoski](#):
>
> But the if else doesn’t display the else.

Please share a repository that reproduces the behavior you mentioned.

You are quoting examples from the Documentation.  
These examples have been reviewed by several people and they do work.

We need to see the context of your project to understand why the `if` and `if else` conditionals do not apply in your setup.

Also please have a look at the [Requesting Help](https://discourse.gohugo.io/t/requesting-help/9132) guidelines for reference.

---

<div class="post-metadata">

**Author:** ![ddanawoski](https://avatars.discourse-cdn.com/v4/letter/d/edb3f5/32.png) [@ddanawoski](https://discourse.gohugo.io/u/ddanawoski)\
**Post date:** [December 2, 2021, 7:50am UTC](https://discourse.gohugo.io/t/documentation-if-and-with-issues/35867/3 "2021-12-02T07:50:10Z")

</div>

> **[GitHub - ddanawoski/practise](https://github.com/ddanawoski/practise)**
>
> Contribute to ddanawoski/practise development by creating an account on GitHub.

I am trying to duplicate what is created on the doc. I am trying to practice a few things actually.

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [December 2, 2021, 7:58am UTC](https://discourse.gohugo.io/t/documentation-if-and-with-issues/35867/4 "2021-12-02T07:58:57Z")

</div>

`.Summary` is available within the context of `.Page`. It is a [page variable](https://gohugo.io/content-management/summaries/#readout).

You have [placed](https://github.com/ddanawoski/practise/blob/main/layouts/_default/baseof.html#L23-L27) the above conditionals within `baseof.html` and `.Summary` returns blank because there is none to be found.

---

<div class="post-metadata">

**Author:** ![ddanawoski](https://avatars.discourse-cdn.com/v4/letter/d/edb3f5/32.png) [@ddanawoski](https://discourse.gohugo.io/u/ddanawoski)\
**Post date:** [December 2, 2021, 8:06am UTC](https://discourse.gohugo.io/t/documentation-if-and-with-issues/35867/5 "2021-12-02T08:06:39Z")

</div>

But .Summary works within the with function.

I have just copied and used same code in single.html within \_default.  
Same issue-

I believe single.html is within the context of .Page in line with the structure of hugo.

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [December 2, 2021, 8:08am UTC](https://discourse.gohugo.io/t/documentation-if-and-with-issues/35867/6 "2021-12-02T08:08:21Z")

</div>

Please update your repo and let me know, so that I can see what you’re doing.

---

<div class="post-metadata">

**Author:** ![ddanawoski](https://avatars.discourse-cdn.com/v4/letter/d/edb3f5/32.png) [@ddanawoski](https://discourse.gohugo.io/u/ddanawoski)\
**Post date:** [December 2, 2021, 8:13am UTC](https://discourse.gohugo.io/t/documentation-if-and-with-issues/35867/7 "2021-12-02T08:13:48Z")

</div>

I have just updated - [GitHub - ddanawoski/practise](https://github.com/ddanawoski/practise)  
I added comments as well

---

<div class="post-metadata">

**Author:** ![ddanawoski](https://avatars.discourse-cdn.com/v4/letter/d/edb3f5/32.png) [@ddanawoski](https://discourse.gohugo.io/u/ddanawoski)\
**Post date:** [December 2, 2021, 8:17am UTC](https://discourse.gohugo.io/t/documentation-if-and-with-issues/35867/8 "2021-12-02T08:17:26Z")

</div>

Baseof is also suppose to work right because the Baseof is the block - So on the page directory - that’s when you open the page - baseof takes on Page variables. Is that not how it works?

**Like a {{.Title}} in Baseof generates differently on each page. Baseof gets inputted to each page**

> [@alexandros](#):
>
> `.Summary` is available within the context of `.Page` . It is a [page variable](https://gohugo.io/content-management/summaries/#readout).
> 
> You have [placed](https://github.com/ddanawoski/practise/blob/main/layouts/_default/baseof.html#L23-L27) the above conditionals within `baseof.html` and `.Summary` returns blank because there is none to be found.

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [December 2, 2021, 8:37am UTC](https://discourse.gohugo.io/t/documentation-if-and-with-issues/35867/9 "2021-12-02T08:37:09Z")

</div>

> [@ddanawoski](#):
>
> Like a {{.Title}} in Baseof generates differently on each page. Baseof gets inputted to each page

Naturally I know what the `baseof.html` template is.

However we were talking about `.Summary`.  
`.Summary` requires `.Content`  
If there is no `.Content` in a content file there is no `.Summary`.

There is at least [one content file](https://github.com/ddanawoski/practise/blob/main/content/about.ar.md) in your repo that does not have any content and hence no `.Summary`.

Anyway I’m sure you will figure it out.  
Or perhaps, one of the others can look into this issue.

---

<div class="post-metadata">

**Author:** ![ddanawoski](https://avatars.discourse-cdn.com/v4/letter/d/edb3f5/32.png) [@ddanawoski](https://discourse.gohugo.io/u/ddanawoski)\
**Post date:** [December 2, 2021, 9:12am UTC](https://discourse.gohugo.io/t/documentation-if-and-with-issues/35867/10 "2021-12-02T09:12:12Z")

</div>

I think the major issue is not the .Summary variable not functioning but the else in the if function not working. As shown on the repo.  
Even a usual text after else does not work. It’s really weird that it doesn’t show up.

```auto
{{if (isset .Params "description")}}
   <h2>{{index .Params "description"}}</h2>
   {{else}}
   <h2>Test if this works - Doesn't work.</h2>
 {{end}}

```

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [December 2, 2021, 9:47am UTC](https://discourse.gohugo.io/t/documentation-if-and-with-issues/35867/11 "2021-12-02T09:47:42Z")

</div>

Most of the content files in the provided repo do _not_ have a `.Description` set in their front matter.

> [@ddanawoski](#):
>
> the else in the if function not working

The conditionals function perfectly well.  
The output depends on what’s entered in the content files.

---

<div class="post-metadata">

**Author:** ![ddanawoski](https://avatars.discourse-cdn.com/v4/letter/d/edb3f5/32.png) [@ddanawoski](https://discourse.gohugo.io/u/ddanawoski)\
**Post date:** [December 2, 2021, 9:53am UTC](https://discourse.gohugo.io/t/documentation-if-and-with-issues/35867/12 "2021-12-02T09:53:37Z")

</div>

My content file is here - [practise/a.md at main · ddanawoski/practise · GitHub](https://github.com/ddanawoski/practise/blob/main/content/oga/a.md)  
I am only testing for this page.

I can go further to investigate other pages and see how that comes out.

---

<div class="post-metadata">

**Author:** ![ddanawoski](https://avatars.discourse-cdn.com/v4/letter/d/edb3f5/32.png) [@ddanawoski](https://discourse.gohugo.io/u/ddanawoski)\
**Post date:** [December 2, 2021, 9:59am UTC](https://discourse.gohugo.io/t/documentation-if-and-with-issues/35867/13 "2021-12-02T09:59:28Z")

</div>

I see the issue now.  
It still returns true when description doesn’t have a value.

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [December 2, 2021, 10:01am UTC](https://discourse.gohugo.io/t/documentation-if-and-with-issues/35867/14 "2021-12-02T10:01:52Z")

</div>

> [@ddanawoski](#):
>
> It still returns true when description doesn’t have a value.

It returns the empty string that you have specified with `description: ""`

---

<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:** [December 4, 2021, 10:02am UTC](https://discourse.gohugo.io/t/documentation-if-and-with-issues/35867/15 "2021-12-04T10:02:00Z")

</div>

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