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

local variable #110

Closed
ezcamlive opened this issue Jun 2, 2019 · 2 comments
Closed

local variable #110

ezcamlive opened this issue Jun 2, 2019 · 2 comments

Comments

@ezcamlive
Copy link

How do I declare a local variable
@counter
and use it in a loop

@jjlauer
Copy link
Member

jjlauer commented Jun 3, 2019

I would suggest you use Rocker's @for command for iterating thru collections. Please consult the syntax docs for more info. There's a very handy "rocker iterator" object that can be included along with iterating that lets you get the current index, check for last/first, etc.

As far as local variable declarations, you would potentially achieve that with the @with command, but I consider creating variables in a template a practice you should try to avoid. I purposefully make it hard to declare variables in the templates since I think it creates spaghetti-like templates. You can either call out to Java methods to achieve a better (more testable) result or redesign your template arguments to accept better prepped data that doesn't need variables. For any iterations, definitely leave that to the @for command.

@jjlauer jjlauer closed this as completed Jun 3, 2019
@ezcamlive
Copy link
Author

Thanks. @for works

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