0

I have this JQuery template:

$.tmpl('<p>${text}</p>', { text: 'cool text' }).appendTo('div');

Works great. but now I want to pass a html parameter into it, but the following won't work.

$.tmpl('<p>${text}</p>', { text: '<span>cool text</span>' }).appendTo('div');

Any suggestions?

1
  • which is the jquery template engine used Commented Feb 8, 2016 at 6:02

2 Answers 2

2

You can use the {{html content}} construct

$.tmpl('<p>{{html text}}</p>', {
  text: '<span>cool text <b>bold</b></span>'
}).appendTo('div');
span {
  color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.js"></script>
<div></div>

Sign up to request clarification or add additional context in comments.

Comments

1

There is one more way you can do it

var markup = "<span>${text}</span>";

jQuery.template( "template1", markup );
jQuery.tmpl( "template1", { text: "cool text" } ).appendTo( "div" );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.