Forum Discussion

PAULEM's avatar
PAULEM
Advisor
6 years ago

Cannot insert Terms of Service using jQuery

I have struggled with this for several days now -- it's driving me nuts!  I want to get our Terms of Service and add it to the FAQ page.  I have created a new section (id = "terms-service" and headi...
  • AdamN's avatar
    6 years ago

    Hi PAULEM ,

    I would suspect that the resulting JavaScript is not well-formed. Let's say your terms of service is:

    <a href="https://www.khoros.com">Click here to learn more</a>

    When this gets rendered, your resulting JavaScript would be:

    $('.tos').html(<a href="https://www.khoros.com">Click here to learn more</a>);

    which is not valid JavaScript.

    Instead you might try something like this:

    $('.tos').html('${text.format('page.user_signup.terms_of_service')?js_string}');

    The ?js_string is a Freemarker built-in to convert a string to be suitable for output into JavaScript strings. And the surrounding single quotes will allow your JavaScript to treat the rendered TOS as a string.

    End the end, this would render to something like:

    $('.tos').html('<a href=\"https://www.khoros.com\">Click here to learn more</a>');

    Which should give you a better result.

    That said, inserting content via DOM manipulation is a practice we typically advise against. This is the "Help"/"FAQ" pages you're talking about, as in /t5/help/faqpage? The sections of the FAQ should be editable via Studio. So I'd be curious to know more about the issue you're encountering. There may be a better way to approach this.