gobuffalo / plush

The powerful template system that Go needs
MIT License
895 stars 57 forks source link

Evaluating pointers #159

Closed gf3 closed 2 years ago

gf3 commented 2 years ago

Perhaps I missed something important in the docs, but plush seems to have issues evaluating pointers:

package main

import (
    "fmt"
    "log"

    "github.com/gobuffalo/plush"
)

type User struct {
    Name *string
}

func main() {
    html := `<html>
  <h1>user.Name: <%= user.Name %></h1>
  <h1>name: <%= name %></h1>
  <h1>name_ptr: <%= name_ptr %></h1>
</html>`

    name := "Cool Guy"
    user := &User{Name: &name}
    ctx := plush.NewContext()
    ctx.Set("user", user)
    ctx.Set("name", name)
    ctx.Set("name_ptr", &name)

    s, err := plush.Render(html, ctx)
    if err != nil {
        log.Fatal(err)
    }

    fmt.Print(s)
}

Go Playground ↑

Output

<html>
  <h1>user.Name: </h1>
  <h1>name: Cool Guy</h1>
  <h1>name_ptr: </h1>
</html>

Is this a known issue? Have I missed something basic?