Rendering HTML from a textarea properly

  • 3
  • Question
  • Updated 2 years ago
  • Answered
Hi,

I'm building a skuid page to display cases (we use email-to-cases), and I'm having difficulty displaying emails.

When I use "textbody" for an email, it displays the text as a long string and not rich text formatting. When I use HTMLbody, it displays the HTML code. I would either like to display the RTF properly, or display the HTML in the email.

I suspect there is a way to do this with running a snippet in the Field Renderer, but I've tried multiple ways to do this and I'm not having luck. Please advise.

Thanks!
Photo of Shane Newman

Shane Newman

  • 200 Points 100 badge 2x thumb

Posted 3 years ago

  • 3
Photo of David Giger

David Giger

  • 1,758 Points 1k badge 2x thumb
Hi Shane,

Should the user be able to edit the email body?
If not you could use a template field, "allow html" and display the HTMLbody in the template field. Afaik the template should render the html body correctly.

Cheers
Photo of Shane Newman

Shane Newman

  • 200 Points 100 badge 2x thumb
I tried this and the HTML is not rendering. It is just showing the raw code.
Photo of Shane Newman

Shane Newman

  • 200 Points 100 badge 2x thumb
Ok, after doing a little more research I'm seeing that even though I "allow HTML", it won't pick up the HTML in {{HTMLbody}}. It only picks up HTML in the "Template" box that I type myself.

Is there a workaround? I even tried wrapping:

<HTML>
{{HTMLbody}}
</HTML>

but it doesn't work.
Photo of Shmuel Kamensky

Shmuel Kamensky, Champion

  • 4,328 Points 4k badge 2x thumb
Shane,

I'm having this exact issue. Did you come up with a solution?
Photo of Shmuel Kamensky

Shmuel Kamensky, Champion

  • 4,328 Points 4k badge 2x thumb
I wanted to display the output of html generated by a Salesforce email template. I used the jQuery replace html function. If you implement this, it would need to be maintained as its dependent on exact html values and DOM hierarchy which skuid could change at any time.

Steps:

1. Create a rich text field for display
2. Note the unique DOM id
3. Create a snippet like below


$ = skuid.$;
var emailTemplateModel = skuid.model.getModel('PreferredEmailTemplate');
var firstRow = emailTemplateModel.getFirstRow();
var htmlValueRaw = firstRow.HtmlValue;
$("#uniqueDOMId > div:first-child").replaceWith(htmlValueRaw);

EDIT:

To reduce the risk of having my jQuery being invalidated by changes, I ended up

  1. Creating a wrapper and using its Id in the jQuery selector
  2. Putting a template in the wrapper (you could still do a rich text field if you want)
  3. Performing the replaceWith function on that template.

I ran into fewer issues using this method.
(Edited)