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

How to use for loop in jet template #116

Closed
aiweisir opened this issue Jun 19, 2019 · 4 comments
Closed

How to use for loop in jet template #116

aiweisir opened this issue Jun 19, 2019 · 4 comments

Comments

@aiweisir
Copy link

How to use for loop in jet template?

@kataras
Copy link
Contributor

kataras commented Jun 21, 2019

{{range id, value := .}}
<li {{if value.Done}}style="color:red;text-decoration: line-through;"{{end}}>
<a href="/todo?id={{ id }}">{{ value.Text }}</a>
{{yield button(label="UP", href="/update/?id="+base64(id))}} - {{yield button(href="/delete/?id="+id, label="DL")}}
</li>
{{end}}

// Range satisfies the jet.Ranger interface and only returns TODOs that are done,
// even when the list contains TODOs that are not done.
func (dt *doneTODOs) Range() (reflect.Value, reflect.Value, bool) {
for dt.i < dt.len {
key := dt.keys[dt.i]
dt.i++
if dt.list[key].Done {
return reflect.ValueOf(key), reflect.ValueOf(dt.list[key]), false
}
}
return reflect.Value{}, reflect.Value{}, true
}

@wx85278161 ^

@kataras
Copy link
Contributor

kataras commented Jun 22, 2019

Although the example doesn't work as expected, try to pass it by value instead: func(dt doneTODOs) Range and it will work, the problem lives on its getRanger's caller eval.go#executeList.NodeRange.expression which makes the ptr as struct value which neither the #112 fixes it, instead it makes the pass by value not work too... something like getRanger(st.context) works for this usecase but probably will have some downsides as I dont know how the whole parser works, author @annismckenzie should take a look at my recommendations. I'll try to fix it by an external map to a ptr to a ptr on the Iris Jet view engine integration but needs a fix on this repository so all users will benefit from it.

@kataras
Copy link
Contributor

kataras commented Jun 22, 2019

The same problem is visible on the Renderer as well, take for example the todo's example func (t *tTODO) Render(r *view.JetRuntime) {. ^

@tooolbox
Copy link
Contributor

@kataras I believe #126 should have fixed this, can you comment?

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

4 participants