Giter Site home page Giter Site logo

Comments (3)

jonnyreeves avatar jonnyreeves commented on July 28, 2024

Hi Peter,

Could you provide a complete example which includes your template markup
and the viewData object in order for me to help you with this issue?

Thanks
On 26 Jun 2013 08:35, "PeterSloth" [email protected] wrote:

Hi

I use the code below to render mark-up for my Preview element.

$('#Preview).mustache('my-template', viewData, { method: 'html' });

The viewData contains fields that contain raw text as well as fields which
contain html markup. The problem is that the html markup is not rendered,
so instead of showing for instance Hello World in bold the Preview element
shows Hello World
Is this a bug or am I doing something wrong?

Thanks
Peter


Reply to this email directly or view it on GitHubhttps://github.com//issues/26
.

from jquery-mustache.

PeterSloth avatar PeterSloth commented on July 28, 2024

Hi John

I tried to include the sample on the web site, but a lot markup was removed which made it unreadable, so I here it is:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript" src="resources/scripts/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="resources/scripts/mustache.js"></script>
    <script type="text/javascript" src="resources/scripts/jquery.mustache.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var viewData = { name: '<b>Jonny</b>' };
            $.Mustache.add('my-template', '<p>Hi, {{name}}, this is an inline template<p>');
            $('#Preview').mustache('my-template', viewData, { method: 'html' });
        });
    </script>
</head>
<body>
    <div id="Preview"></div>
</body>
</html>

from jquery-mustache.

jonnyreeves avatar jonnyreeves commented on July 28, 2024

mustache.js automatically HTML-escapes all tags wrapped in {{ }}'s. If you don't want mustache.js to HTML-escaped then you need to use either triple mustaches ({{{name}}}) or an ampersand in front the variable name {{&name}}

So your code should be changed to read:

$.Mustache.add('my-template', '<p>Hi, {{{name}}}, this is an inline template with HTML Markup<p>');

from jquery-mustache.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.