BorisMoore / jsrender

A lightweight, powerful and highly extensible templating engine. In the browser or on Node.js, with or without jQuery.

Home Page:http://www.jsviews.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use question

ilovetogetspamed opened this issue · comments

I have the following test file:

<!DOCTYPE html>
<!-- To run the current sample code in your own environment, copy this to an html page. -->

<html>
<head>
  <script src="http://code.jquery.com/jquery-3.3.1.min.js"></script>
  <script src="http://www.jsviews.com/download/jsrender.min.js"></script>
  <link href="http://www.jsviews.com/samples/samples.css" rel="stylesheet" />
</head>
<body>

<div id="result"></div>

<script id="theTmpl" type="text/x-jsrender">
<div>
   <em>Name:</em> {{:name}}
   {{if showNickname && nickname}}
      (Goes by <em>{{:nickname}}</em>)
   {{/if}}
   {{if (nickname == "Sue")}}
      (Hello <em>{{:nickname"}}</em>)
   {{/if}}
</div>
</script>

<script>
var data = [
  {
    "name": "Robert",
    "nickname": "Bob",
    "showNickname": true
  },
  {
    "name": "Susan",
    "nickname": "Sue",
    "showNickname": false
  }
];

var template = $.templates("#theTmpl");

var htmlOutput = template.render(data);

$("#result").html(htmlOutput);
</script>

</body>
</html>

I was hoping that my test for (nickname == "Sue") would have produced:

Name: Robert (Goes by Bob)
Name: Susan (Hello Sue)

Instead I get

Name: Robert (Goes by Bob)
Name: Susan (Hello [object Object])

I tested in both Safari and Chrome with the same results. Note: I did appended the 'http:' to the script tags' src for it to work locally.

You have

(Hello <em>{{:nickname"}}</em>)

(extra ") instead of

(Hello <em>{{:nickname}}</em>)

I assume that is the problem.

Wow, not my day. Sorry. It works great now! Thanks for all hard work on jsrender.