BATMAN_2008
BATMAN_2008

Reputation: 3530

Hugo/Docsy: execute of template failed at <.url>: can’t evaluate field url in type bool

I am developing a static web application using Hugo with Docsy theme. I would like to add an condition within Docsy Partials code where I would like to append the mailTo: word to my .url if the .mail is set to true, when I try to do this then I get the following error:

/themes/docsy/layouts/partials/footer.html:36:34": execute of template failed at <.url>: can’t evaluate field url in type bool 

Following is the code I am adding to my partials:

{{ $myUrl := "" }}
{{ with .mail }}
 {{ $myUrl = print "mailTo:" .url }}
{{ else }}
 {{ $myUrl = .url }}
{{ end }}
    
{{ $myUrl }}

If I add some test then everything would work perfectly:

{{ with .mail }}
 TRUE
{{ else }}
 FALSE
{{ end }}

I am quite new to the Hugo and Docsy theme so finding difficult to understand and fix it. Any help would be really appreciated.

Upvotes: 0

Views: 709

Answers (1)

Mr. Hugo
Mr. Hugo

Reputation: 12592

You are not using with correct here: https://gohugo.io/functions/with/. I think you should use if here.

Upvotes: 1

Related Questions