PageProperty and IF Inline Condition

I use the pageProperty function to manage some of my menus that are in my layout. I need to apply certain classes to the links, depending on what metadata the Property page returns. Right now, it looks like this ...

<g:if test="${pageProperty(name:'meta.nav') == 'support'}">  <g:link class="selected" ...>support</g:link> </g:if> <g:else>  <g:link ...>support</g:link> </g:else> 

I would like to clear this, however this does not work.

 <g:link class="${pageProperty(name:'meta.nav') == 'support' ? selected : null}" ...>support</g:if> 

I tried several different options for paranthesis and no one seems to get what I need. For instance:

 ${(pageProperty(name:'meta.nav') == 'support') ? selected : null} ${(pageProperty(name:'meta.nav') == 'support' ? selected : null)} 

It just doesn't seem to be acting correctly. Any help is appreciated.

+4
source share
2 answers

Like a wild blow in the dark, how about:

 ${ pageProperty(name:'meta.nav').equals( 'support' ) ? 'selected' : null } 

Not like groovy, but might be less confusing for the parser (it seems like something is confused somewhere and resets == support where it shouldn't)

+3
source

I would try to make a true condition as a string:

 ${(pageProperty(name:'meta.nav') == 'support') ? 'selected' : null} 

Perhaps he is trying to access a variable named selected in a GSP script that will be undefined.

Hope this helps.

+1
source

Source: https://habr.com/ru/post/1390688/


All Articles