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

@with variables cannot reference those within the same @with #125

Open
albert-kam opened this issue Jan 2, 2020 · 4 comments
Open

@with variables cannot reference those within the same @with #125

albert-kam opened this issue Jan 2, 2020 · 4 comments

Comments

@albert-kam
Copy link

So i have this @with in my template:

@with(MyFields fields = getMyFields(),
        nameField = fields.get("name"),
        passwordField = fields.get("password")) {
    my template content here
}

This will cause

error cannot find symbol
  symbol:   variable fields

But .. when i do this instead, it runs okay.

@with(MyFields fields = getMyFields()) {
    @with(nameField = fields.get("name"),
            passwordField = fields.get("password")) {
        my template content here
    }
}

Preferably for me though is that all vars within a single @with should be able to see one another, without having to resort to nested @with-s.

Thank you ...

@jjlauer
Copy link
Member

jjlauer commented Jan 7, 2020

@albert-kam I'd certainly be open to making the multi-with statement version work as well if you were interested in creating a PR and the unit tests. As you point out, nested with statements will always work if you need to work with multiple variables.

@sysmat
Copy link

sysmat commented Sep 26, 2020

  • java 8
  • rocker 1.3.0
    The syntax is not very clear at
    With blocks (set one or more variables) (@with)

Wen using this snippet:

@with (Collection<OrgLocation> locs = org.getLocations())) {
    @views.locationsFrag.template(locs) -> {}
}

I got a compile error: cannot find symbol variable with

Even basic not working, I'm doing something wrong?

  • What I actually wont to achieve: call a function to filter a collection of locations and then pass it to another template, is this even possible?
  • In template when calling java function which returns class can it be set to a variable in the template?

Sample:

@import si.arnes.db.aris.bean.Organization
@import si.arnes.db.aris.bean.OrgLocation
@import static views.Utils.filterPostalLocations
@import java.util.Collection

@args (Organization org, RockerBody content)
Organizacija:   @org.getName()
Matična:        @org.getRegistrationNumber()
Koda:           @org.getCode().name()
@with (Collection<OrgLocation> locs = filterPostalLocations(org.getLocations()))) {
   @views.locationsFrag.template(locs) -> {}
}

@albert-kam
Copy link
Author

Does it work without @with ?

@sysmat
Copy link

sysmat commented Oct 5, 2020

yes it works, I do it @views.locationsFrag.template(filterPostalLocations(org.getLocations())) -> {}

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

3 participants