Documentation if and with issues

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 }}

Kindly help if you have insight into this.

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 guidelines for reference.

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

.Summary is available within the context of .Page. It is a page variable.

You have placed the above conditionals within baseof.html and .Summary returns blank because there is none to be found.

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.

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

I have just updated - GitHub - ddanawoski/practise
I added comments as well

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

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 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.

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.

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

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

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

2 Likes

My content file is here - practise/a.md at main · ddanawoski/practise · GitHub
I am only testing for this page.

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

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

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

1 Like

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