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 can I write and condition in g:if tag? #8

Open
fatshotty opened this issue Jan 16, 2013 · 6 comments
Open

how can I write and condition in g:if tag? #8

fatshotty opened this issue Jan 16, 2013 · 6 comments
Assignees

Comments

@fatshotty
Copy link

Hello,
I'm using your haml4grails plugin.
It saves me ;)

Unfortunately, i have something like this:

%g:if(test="${myobj && mysecondObj}")
   .... my code

it will be converted into

<g:if test="${myobj &amp;&amp; mysecondObj}" >
  ... my code

and it make compiler crashes because of &amp;

So, my question is: how can I avoid this error?
I need and condition working.

Thanks in advance

@raymyers
Copy link
Owner

What version of Grails are you using?

@ghost ghost assigned raymyers Jan 16, 2013
@fatshotty
Copy link
Author

Thanks for replying

Grails version 2.1.1
Haml4Grails works fine but the && condition :-/

@raymyers
Copy link
Owner

JHaml doesn't know to skip HTML escaping within a ${...} expression for attribute values. Thanks for bringing that to light, I'm working on fixing it.

In the mean time, try putting the expression itself in parens with no quotes. Haml syntax recognizes that as an expression.

%g:if(test=(myobj && mysecondObj))

Should resolve to:

<g:if test='<%= (myobj && mysecondObj) %>'></g:if>

Let me know if that helps.

@fatshotty
Copy link
Author

Hello,
thanks for the hack
Unfortunately the result is:
%li(class=(params.controller == 'suppliers' && isAdmin ? 'selected' : ''))
it becomes:
<li class="&lt;%= (params.controller == 'suppliers' &amp;&amp; isAdmin ? 'selected' : '') %&gt;">
and in the page I see (using debugbar on firefox):
<li class="<%= (params.controller == 'suppliers' && isAdmin ? 'selected' : '') %>">
and it is not the expected behavior :-/

I have tested around but nothing good :(

Thanks

@raymyers
Copy link
Owner

I've now fixed this in JHaml 0.1.5. Attribute values which look like they have ${}... expression language in them are not escaped.

Haml4Grails 0.4 includes it - you can try out the zipped plugin here:
https://github.com/raymyers/haml4grails/tree/master/dist

I'll publish it to the official Grails plugin repo once it's ready.

It's built against Grails 1.3.9, so let me know if there is trouble importing into 2.1.1 - I had some issues getting the dependencies to come through when installing into 2.2.0.

Update:
Apparently the dependency strategy for plugins has changed with Grails 2, so I'll have to make some more changes

Another idea for a workaround:
- def tempClassVar = (params.controller == 'suppliers' && isAdmin ? 'selected' : '')
%li(class="${tempClassVar}")

@fatshotty
Copy link
Author

Thanks a lot.
I'll try and let u know soon ;)

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