ubccr / mokey

FreeIPA self-service account management portal
BSD 3-Clause "New" or "Revised" License
190 stars 45 forks source link

Unable to add an img to layout.html in the {{with .user}} section #107

Closed Sahrarara closed 2 years ago

Sahrarara commented 2 years ago

Like the title says I am unable to add a simple img tag with a path into the .user section of the layout.html without it breaking. Outside of that section the img tag with the path works and I get the image I want to be shown.

Here is the error log:

  time="2021-11-24T12:03:30Z" level=info msg="Redirect URL" wyaf=/
  {"time":"2021-11-24T12:03:33.874434906Z","level":"ERROR","prefix":"echo","file":"server.go","line":"68","message":"template: layout.html:53:25: executing "layout" at <.ctx>: can't evaluate field ctx in type *ipa.UserRecord"}
  time="2021-11-24T12:03:34Z" level=error msg="Requested path not found" ip=84.115.239.187 path=/favicon.ico
  {"time":"2021-11-24T12:03:34.061972807Z","level":"ERROR","prefix":"echo","file":"server.go","line":"68","message":"code=404, message=Not Found"}
  time="2021-11-24T12:03:43Z" level=info msg="rate limiting" counter=2 path=/auth/login remoteIP=77.118.133.86
  time="2021-11-24T12:03:43Z" level=info msg="Redirect URL" wyaf=/
  {"time":"2021-11-24T12:03:43.846462404Z","level":"ERROR","prefix":"echo","file":"server.go","line":"68","message":"template: layout.html:53:25: executing "layout" at <.ctx>: can't evaluate field ctx in type *ipa.UserRecord"}
  {"time":"2021-11-24T12:03:44.844935733Z","level":"ERROR","prefix":"echo","file":"server.go","line":"68","message":"code=404, message=Not Found"}
  time="2021-11-24T12:03:44Z" level=error msg="Requested path not found" ip=84.115.239.187 path=/favicon.ico

It seems like the path in the img tag is not recognized and thus throwing errors. I assume it is probably something trivial as I'm rather new to programming in general, but I cannot figure it out. Other content which is added to the .user works as intended. New divs with bootstrap classes work without issue.

aebruno commented 2 years ago

Did you try this?

<img src="{{ uri $.ctx "/static/images/YOUR-IMAGE.png" }}"

Note, inside the {{with .user}} you need to add the $.ctx. If that doesn't work please provide your template code you're trying to run.

Sahrarara commented 2 years ago

Thank you so much! I was under the impression that images did not need $.ctx since the mokey-portal.png also didn't need it.