I am new in grails and trying to set value from messages.property (i18n) in g:set tag on gsp and then use it in java script on the same gsp page. For example:
my messages.property should look like: operation.hello=Hello '{0}'
in the gsp there should be:
<g:set var="foo" value="${operation.hello('Patty')}" scope="page"/>
and
<g:javascript>
alert( $foo )
</g:javascript>
not sure how to handle this.Can anyone help?
our basic intention is to use a parametrized-messages.property value from javascript.
Tried JAWR plug-in and that worked well but JAWR had other issues that we do not want in our case
So long as you understand that all this is pocessed on the server side, I think all you need to do is use the correct syntax:
<g:set var="foo" value="${g.message(code: 'operation.hello', args: ['Patty'])}" scope="page"/>
<g:javascript>
alert( "${foo}" );
</g:javascript>
By the time this reaches the browser, it should simply read:
<script type="text/javascript">
alert( "Hello Patty" );
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With