Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Adding html tags to placeholders in APEX email templates

JoBobJul 8 2020

I want to use APEX email templates (version 19.1), in particular the preview (apex_mail.prepare_template).  For a given placeholder in the template, I may have a list of items.  For example, a template that contains order details might have a placeholder #ITEMS# that could be a list of things such as "Apples", "Oranges".  I wanted to pass in html tags such as <br> or table tags so that the output would be formatted nicely.  However, once I call apex_mail.prepare_template with a string containing those tags, the output returns the tags as "&lt;" or "&gt;" and as such, the actual "<" or ">" sign is displayed in my output. 

I have tried passing in escaped values as placeholders but the result is the same. I created two test cases:

1. use APEX_JSON.write to create the CLOB for the placeholder. Placeholder passed value in looks like this: This is some details:\u003Cbr\u003EMore Info

2. use APEX_JSON.stringify for the placeholder value. Placeholder looks like this: This is some details:<br>More Info

Output of apex_mail.prepare_template looks like this in either case:  This is some details:&lt;br&gt;More Info

Test case 1 using JSON.write

DECLARE

  l_subject             VARCHAR2(4000);

  l_body_html           CLOB;

  l_body_text           CLOB;

  v_detail        varchar2(4000);

  l_place_holders CLOB;

BEGIN  

v_detail:='This is some details:<br>More Info';

    APEX_JSON.initialize_clob_output;

    APEX_JSON.open_object; -- { Outer Object

    APEX_JSON.write('NOTIF_DETAILS', v_detail);

    APEX_JSON.close_object; -- } Outer Object

    l_place_holders := APEX_JSON.get_clob_output;

    APEX_JSON.free_output;

apex_mail.prepare_template

    (p_static_id      => 'K2TEST',

     p_placeholders   => l_place_holders,

     p_application_id => 104,

     p_subject        => l_subject,

     p_html           => l_body_html,

     p_text           => l_body_text);

dbms_output.put_line (l_body_html);

END;

Test Case 2  using JSON.stringify

BEGIN

v_detail:='This is some details:<br>More Info';

apex_mail.prepare_template

    (p_static_id      => 'K2TEST',

     p_placeholders   => '{' ||

                         '   "NOTIF_DETAILS":'    || apex_json.stringify(v_detail) ||

                         '}',

     p_application_id => 104,

     p_subject        => l_subject,

     p_html           => l_body_html,

     p_text           => l_body_text);

dbms_output.put_line (l_body_html);

END;

Any way to get around this issue or perhaps a better way to do this altogether?  Thank you.

Comments
Post Details
Added on Jul 8 2020
1 comment
1,964 views