Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🤗 [Question]: How do I render conditionals in Pug #393

Closed
3 tasks done
AxelRHD opened this issue Aug 29, 2024 · 3 comments
Closed
3 tasks done

🤗 [Question]: How do I render conditionals in Pug #393

AxelRHD opened this issue Aug 29, 2024 · 3 comments
Labels
🤔 Question Further information is requested

Comments

@AxelRHD
Copy link

AxelRHD commented Aug 29, 2024

Question Description

I really love to see that Fiber is supporting Pug for templates.

Just fiddling around but I can't get a simple example to work.

Title is working, the conditional not.

Rendering in handler:

app.Get("/hello", func(c *fiber.Ctx) error {
        return c.Render("hello", fiber.Map{
                "Title":    "Hello from Fiber with Pug!",
                "LoggedIn": true,
        })
})

Getting the following warning: 2024/08/29 23:47:08.480286 app.go:999: [Warn] failed to load views: template: hello:2: unexpected "#" in if

Code Snippet (optional)

h1.title #{ .Title }

if #{ .LoggedIn }
  p Hello User!
else
  p Hello Stranger!

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my questions prior to opening this one.
  • I understand that improperly formatted questions may be closed without explanation.
@AxelRHD AxelRHD added the 🤔 Question Further information is requested label Aug 29, 2024
@AxelRHD
Copy link
Author

AxelRHD commented Aug 29, 2024

This one is also not working:

- var loggedIn = #{ .LoggedIn }
h1.title #{ .Title }

if loggedIn
        p Hello User!
else
        p Hello Stranger!

@AxelRHD
Copy link
Author

AxelRHD commented Aug 29, 2024

Sometimes it is simpler than expected:

h1.title #{ .Title }

if .LoggedIn
  p Hello User!
else
  p Hello Stranger!

Maybe a short example can be added to the documentation?

@AxelRHD AxelRHD closed this as completed Aug 29, 2024
@efectn
Copy link
Member

efectn commented Aug 29, 2024

Sometimes it is simpler than expected:

h1.title #{ .Title }

if .LoggedIn
  p Hello User!
else
  p Hello Stranger!

Maybe a short example can be added to the documentation?

Sure, you can create a PR to demonstrate Pug syntax and behavior in docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤔 Question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants