Freemarker output $ and special symbols such as HTML tags

Source: Internet
Author: User

Scenario: Programmers do not like to read the document, but prefer to copy the example. Therefore, we have made the components of the Platform group into examples for others to refer to. We use the front-end display layer is freemarker, so encountered this problem, such as we want to let the front-end display Freemarker own source code when there is a problem (because our example program's page is also used Freemarker). The following problems are encountered:

1, how to display the HTML source code, rather than let the browser parse the HTML, by using Freemarker HTML escape.

For example, we show the IMG tag, that is: ${' "html}, so that the final content on the page is: , and will not be parsed by the browser.

2, display Freemarker source code, such as ${} symbol, you can be as follows:

${R' ${obj.name} '}, so the final result is: ${obj.name}, not parsed by Freemarker. It is important to note that the "R" character in front of the red is the key point.

3, custom macro end symbol can not come out of the solution: for example, we have customized a macro called:< @cfw. column></@cfw. column> If you want to show the source, the end of the symbol "</@cfw .column> "Is not shown, this time can be used in the way of character escapes, such as:

${' &lt;/@cfw. Column '}, which shows the result: </@cfw .column>


Not what the technical content of things, write down to prevent forgetting, also by the way to help you solve some problems.

Freemarker output $ and special symbols such as HTML tags

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.