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

Function call fails with an error from reflect. #25

Open
justinas opened this issue Jul 12, 2014 · 1 comment
Open

Function call fails with an error from reflect. #25

justinas opened this issue Jul 12, 2014 · 1 comment

Comments

@justinas
Copy link

Using this code:

package main

import (
    "log"
    "os"

    "github.com/eknkc/amber"
)

func hasData() bool {
    return true
}

var tmpl = `p
    .has-data ? hasData()`

func main() {
    amber.FuncMap["hasData"] = hasData

    compiler := amber.New()
    compiler.Parse(tmpl)
    c, err := compiler.Compile()
    if err != nil {
        log.Fatal(err)
    }
    err = c.Execute(os.Stdout, nil)
    if err != nil {
        log.Fatal(err)
    }
}

Results in this error:

reflect: call of reflect.Value.Type on zero Value

I've been looking at this for days. Am I plugging the function in wrong? Are (non-builtin) functions disallowed in conditional argument conditions? Or is this just a bug?

@zserge
Copy link

zserge commented Aug 30, 2015

I have a similar issue. Seems like Amber compiles function call foo() as {{call .foo}}. However, there is no method foo() in the data bound (you pass nil as your template data), thus the error.

I was able to work around this by passing a map of interface{} into c.Execute like c.Execute(os.Stdout, map[string]interface{}{"hasData": hasData})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants