Search the FirstSpirit Knowledge Base
Dear Team,
How to do encoding of & in the mailto subject in the FS 5.2.2109?
1.First Option:
--$$CMS_IF(fs_portal_pageTitle != null && !fs_portal_pageTitle.isEmpty)$$CMS_VALUE(fs_portal_pageTitle)$%0D%0A$CMS_END_IF$$--
After & symbol text and the remaining things in subject line is missing.seethe image below.
?subject=You have received a recommendation&body=Dear Sir or Madame,%0D%0Athe sender of this e-mail would like to recommend a link to you%0D%0A%0D%0ATest Module & Page Display%0D%0Ahttps://inside-ws-d.bosch.com/FIRSTspiritWeb/permlink/wcms_c_-standard_page_33-EN%0D%0A%0D%0AThank you
2. Second Option:
--$$CMS_IF(fs_portal_pageTitle != null && !fs_portal_pageTitle.isEmpty)$$CMS_VALUE(fs_portal_pageTitle.replaceAll("&", "%26"))$%0D%0A$CMS_END_IF$$--
$CMS_VALUE(fs_portal_pageTitle.replace("&", "%26")$
?subject=You have received a recommendation&body=Dear Sir or Madame,%0D%0Athe sender of this e-mail would like to recommend a link to you%0D%0A%0D%0ATest Module & Page Display 55%0D%0Ahttps://data.com/wcms_c_-standard_page_33-EN%0D%0A%0D%0AThank you
Image:
3.Third Options:
$CMS_VALUE(fs_portal_pageTitle.replace("&", "&").urlEncode,default:"")$
$CMS_VALUE(class("java.net.URLEncoder").encode(fs_portal_pageTitle.toString().trim(), "UTF-8"))$
I have tried all the above options nothing worked for me.
Thank you.
Hello Michael,
Thank you for your answer and time on this issue. really its helpful for me to understand the things much better.
convertEntities="quote" is removed for the below component,
<CMS_INPUT_TEXTAREA name="fs_portal_pageTitle" ....... ... .. . />
Every thing works except gg+g&h, its changed into gg%20g&h. This is shown in the previous thread also. Except this problem all the other things are working fine and good.
Result:
Also some change in the code works for me even with convertEntities="quote" is enabled for the component, This is working for me.
$-- Build the body content--$
$CMS_SET(set_adviceBodyPlain)$
$CMS_VALUE(if(#global.language.abbreviation.equals("DE"),
"Sehr geehrte Dame,
sehr geehrter Herr,Ader Absender dieser E-Mail möchte Ihnen eine Empfehlung aussprechen \n",
"Dear Sir or Madame,
the sender of this e-mail would like to recommend a link to you \n"
))$
$CMS_VALUE(if(fs_portal_pageTitle != null && !fs_portal_pageTitle.isEmpty,fs_portal_pageTitle))$
$CMS_VALUE(ps_publishingHost)$$CMS_VALUE(ps_permLinkContext)$$CMS_RENDER(script:"permlinkcreator", element:#global.node)$
$CMS_VALUE(if(#global.language.abbreviation.equals("DE"),
"\n Vielen Dank",
"\n Thank you"
))$
$CMS_END_SET$
$-- Unescapes a string containing entity escapes to a string containing the actual Unicode characters --$
$CMS_SET(set_adviceBodyHtmlDecoded)$$CMS_VALUE(class("org.apache.commons.lang.StringEscapeUtils").unescapeHtml(set_adviceBodyPlain.toString().trim()))$$CMS_END_SET$
$-- This method uses the supplied encoding scheme to obtain the bytes for unsafe characters. --$
$CMS_SET(encodedBody)$$CMS_VALUE(class("java.net.URLEncoder").encode(set_adviceBodyHtmlDecoded.toString().trim(), "UTF-8"))$$CMS_END_SET$
$-- Spaces are converted into ‘+‘ signs. --$
$CMS_SET(encodedBody, encodedBody.toString.replace("+", "%20"))$
<li><a href="mailto:?Content-Type=text/html&subject=$CMS_VALUE(set_adviceSubject)$&body=$CMS_VALUE(set_encodedBody)$" title="$CMS_VALUE(pt_l... ... .. . ) </li>
Thank you.
Regards,
Siva
Hi Siva,
can you please check your conversion rule. Maybe this is the reason why %26 gets &.
Best regards
Jan
Hi Jan,
Thank you for your reply and time. Looks like conversion rules given properly.
Listed out the image for your reference,
--$$CMS_IF(fs_portal_pageTitle != null && !fs_portal_pageTitle.isEmpty)$$CMS_VALUE(fs_portal_pageTitle.convert2.replace("&", "%26").urlEncode,default:"")$%0D%0A$CMS_END_IF$$--
Output: Test+Module+%26amp;amp;+Page+Display+3
How to make it to display & in between like below,
Test Module & Page Display 3
Thank you,
Regards,
Siva
Hi Siva,
I think you are mixing too many things/conversions together here (especially by combining "manual" encoding with method calls). In general, .convert2 encodes content to be displayed in HTML and is the wrong conversion for URL parameters.
My advice is to first build up the complete content of the mail body in a plain string variable (without any replacements, manual "encoding" of blanks etc. or conversions!) and then as a last step just do the urlEncode for the complete string.
Example:
$CMS_SET(set_adviceBody)$
...
$CMS_IF(fs_portal_pageTitle != null && !fs_portal_pageTitle.isEmpty)$$CMS_VALUE(fs_portal_pageTitle)$$CMS_END_IF$
...
$CMS_END_SET$
...
<a href="mailto:....?subject=...&body=$CMS_VALUE(set_adviceBody.toString().urlEncode())$">Mail</a>
Michael
Hi Michael,
Thank you for your detailed reply and time.
My problem is &(ampersand) symbol not displaying in the email properly.(Test Module & Page Display 1) Without & my existing code works fine.
I have all the (manual encoding and blanks and conversions, but need to consider next line of text and other format) and created a plain content which need to generated in mailto option.
Below image for your reference,
$CMS_SET(set_adviceSubject,if(#global.language.abbreviation.equals("DE"),"Sie haben eine Empfehlung erhalten","You have received a recommendation"))$
$CMS_SET(set_adviceBody)$
$CMS_IF(#global.language.abbreviation.equals("DE"))$
Sehr geehrte Dame,sehr geehrter Herr,Ader Absender dieser E-Mail möchte Ihnen eine Empfehlung aussprechen
$CMS_ELSE$
Dear Sir or Madame, the sender of this e-mail would like to recommend a link to you
$CMS_END_IF$
$CMS_IF(fs_portal_pageTitle != null && !fs_portal_pageTitle.isEmpty)$
$CMS_VALUE("Test Module & Page Display 1".toString())$
$CMS_END_IF$
$CMS_VALUE(ps_publishingHost)$$CMS_VALUE(ps_permLinkContext)$$CMS_RENDER(script:"permlinkcreator", element:#global.node)$
$CMS_IF(#global.language.abbreviation.equals("DE"))$Vielen Dank$CMS_ELSE$Thank you$CMS_END_IF$
$CMS_END_SET$
<li><a href="mailto:?subject=$CMS_VALUE(set_adviceSubject)$&body=$CMS_VALUE(set_adviceBody.toString().urlEncode())$" title="$CMS_VALUE(pt_langswitch.advisePage_help)$"><img src="$CMS_REF(media:"leer")$" class="sprite_empfehlenicon_liste">$CMS_VALUE(pt_langswitch.advisePage)$</a></li>
Below image is the Result of Above code:
Actual Result Should be like below image (of mail to):
Hi Siva,
I suppose „fs_portal_pageTitle“ comes from an input component. Can you post it‘s code please?
Or does it even not work when you use the version without input component?
Michael
Hi Michael,
Yes its a input component from Standardpage. convertEntities value is 'quote'.
Its nothing but page title as shown in the below image -- 'fs_portal_pageTitle' .
Thank you.
Regards,
Siva
Hi Siva,
that‘s at least a part of the problem. I generally recommend to NEVER use converEntities in a form definition but instead only use the proper conversion in the output channel, e.g. .convert2 for the HTML output on a page.
convertEntities leads to various problems especially like yours 😉
In your case the convertEntities already does a conversion when accessing the variable which is wrong here as you have to urlEncode the original string, not an already converted one.
Michael
Hi Michael,
Yes the specific component is already converted and again converting it leads to problem.
Finally resolved the problem as like below,
--$$CMS_IF(fs_portal_pageTitle != null && !fs_portal_pageTitle.isEmpty)$$CMS_VALUE(fs_portal_pageTitle.replaceAll("&","%26"))$%0D%0A$CMS_END_IF$$--
Thank you for your kind support Mr.Michael. Really it is helpful to understand the problem more in detail for FirstSpirit topics.
Regards,
Siva
Hi Siva,
you‘re welcome. But to be honest I think your approach is a little „ugly“ because you are just „manually undoing“ a generally wrong conversion.
This may lead to problems in the future - e.g. if the title contains a < or > etc. because your solution is just an incomplete workaround 😉
I‘d really recommend the „clean“ approach of removing the convertEntities and the „manual“ encoding and adding .convert2 for the page output.
Michael