Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails: How to include an html link inside a <g:message> default attribute?

I am starting with Grails and want to have one page with multilanguage content.

I started using the tag which works fine. But here is what I want to do:

I want to include the default text of the default language right in the text, to avoid switching back and forth in between files.

<g:message code="homepage.feature.headline1" default="This is an english text" />

The above works.

But now I a have a message which should include a link like this:

<g:message code="homepage.feature.headline1" default="This is an english text with <a href='somefile.html'>a link</a>" />

This gives me an exception:

org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error processing GroovyPageView: Grails tags were not closed! [[<g:message>]] in GSP 

How can I achieve that I can include a link there? I have tried escaping the <> brackets but still no luck. I really would like to avoid splitting up this one sentence into multiple smaller sentences.

Thanks Christoph

like image 201
Christoph Avatar asked Jan 18 '26 00:01

Christoph


1 Answers

Closures can be used for nested i18n messages. I find it useful for when the link generation needs additional logic.

<g:message code="homepage.feature.headline1" default="This is an english text with a {0}" encodeAs="raw" args="[link(controller: 'someController', action: 'someAction') { message(code:'homepage.feature.headline1.link')}]"/>
like image 145
Szymon Avatar answered Jan 20 '26 22:01

Szymon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!