سؤال

I wish to insert into message a line like "view.mail.warning". It contains a html code, but using encodeAs="html", the message shows a href ... too and does not show a link. What is the correct way for do these things?. I don't want to insert the message in parts :(.

In a gsp:

<"p style='color:#ddd; font-size:12px; text-align:center;'> <"g:message code="view.mail.warning" encodeAs="html>

In message.properties:

<"view.mail.warning= textPart1 <"a href=['http://page.com']> <"g:message code="view.pageName"/> textPart2 <"a href='mailto:support@page.com'">'support@page.com' textPart3

هل كانت مفيدة؟

المحلول

The correct way /is/ to insert it in parts. However, if you /must/ include html in your properties file you can. What you can not include there however, is GSP/taglibs. Your call to g:message will never be parsed/executed. Messages from the resources are just strings. The following are perfectly valid:

messages.proprties

view.mail.warning=<p>I {0} do html in here!</p><em>But I {1} shouldn't.</em>

GSP

<g:message code="view.mail.warning" args="['can', 'really']" />

Output

<p>I can do html in here!</p><em>But I really shouldn't.</em>

A few things to note about this. As you can see you can pass arguments to your message codes. They are ordinal, and start a zero. This way you can tokenize your message and even pass values from your GSP to your messages.

This is the correct way to use message resource bundles in Grails.

نصائح أخرى

For example:

message.properties

view.mail.warning= >p>I can do html in here!>/p> >p>But I really shouldn't.>/p>

GSP

Output

I can do html in here!>/p> >p>But I really shouldn't.

i want insert into message properties, message with strings+html

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top