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

iteration loop doesn't recognize page level data #45

Open
stephenhu opened this issue Apr 26, 2016 · 2 comments
Open

iteration loop doesn't recognize page level data #45

stephenhu opened this issue Apr 26, 2016 · 2 comments

Comments

@stephenhu
Copy link

if i pass a struct into an amber template, i can't seem to access the variables inside of an iteration block:

let's say i have this struct:

type Foo struct {
ID string
OK bool
Bar []string
}

// initialized here
f = Foo{ID: "abc", OK: true, Bar: make([]string){"ddd", "eee"}}

passed into the template.Execute function:

template.Execute(w, f)

i can do the following without any issues:
h3 #{ID} // h3 abc

but if i do this:

each $i in Bar
h3 #{$i} // works fine
h3 #{ID} // causes an Amber Error <>: Unable to parse expression

exact error is:
Amber Error in <static/templates/viewteam.amber>: Unable to parse expression. - Line: 62, Column: 21, Length: 2

@stephenhu
Copy link
Author

there's a workaround which is to assign the page level variable to a variable:

e.g.

$id = ID

each $i in Bar
h3 #{$i} // works fine
h3 #{$id} // this works

@stephenhu
Copy link
Author

i would say this is a fairly serious limitation, seems nested loops or nested maps also have the same issue and the work around is not very apparent to me at the moment.

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

1 participant