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 heading exists with class of "lia-terms-service"). I have tried about 20 different ways to insert our TOS.
This is where I gave up and posted this plea for help!
$('.lia-terms-service').prepend('<div class="tos lia-faq-answer"></div>');
$('.tos').html(${text.format('page.user_signup.terms_of_service')});
If I comment out the second line, the new DIV is prepended and all is good -- but it has nothing in it. When I include the insertion, it falls over.
Does anyone have any ideas? I'm sure there's a way but it has so far evaded capture!
Thanks
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.