jsrender

Error when loading jsrender templates through AJAX

那年仲夏 提交于 2019-12-06 04:43:25
I am trying to write a function to load templates in external files and use them with jsrender . However, I am getting this error: TypeError: elem.getAttribute is not a function [Break On This Error] value = $templates[elem.getAttribute(tmplAttr)]; I have some console.logs showing that the template was retrieved with ajax. The basic code that causes the error is as follows: var path = 'templates/myTemplate.tmpl.html'; var data = searchResultTeasers; var target = $('#results'); $.ajax({ url : path, aysnc : false, success : function(template) { console.log("Path", path); console.log("Template",

jsRender Rendering HTML

空扰寡人 提交于 2019-12-05 10:36:47
I'm using jsRender to render my data on html page. The data gets rendered perfectly. However, in some content items, HTML text (like hyperlink) appears as text. In jquery template, there is a way to render HTML by {{html. Is there anything similar available in jsRender? My code is as follows: <p> {{ =Status}} //need to convert this to HTML so it should appear as hyperlink. </p> Thanks. jquery html templates jsrender share | improve this question The JsRender beta candidate is now out (see Boris' post from last night http://www.borismoore.com/2012/03/approaching-beta-whats-changing-in_06.html )

Call JavaScript function from JsRender

安稳与你 提交于 2019-12-04 18:00:19
问题 I have a JsRender template. When template is rendering I want to call a JavaScript function to manipulate some data. Here is my JsRender template. <tr class="template-download"> <td class="size"> <span>{{:size}}</span> </td> </tr> Now I want to pass :size value to JavaScript function and get the return value. So I can show return value instead of :size value. My JavaScript function is function getSize(size) { var megabytes = size / (1024 * 1024); return megabytes.toFixed(2) + "MB"; } How can

How to change JsRender template tags?

隐身守侯 提交于 2019-12-04 04:33:58
问题 I use Twig. It uses these tags: {{ name }} I want to include JsRender in my project. But JsRender also uses the same tags {{:name}} , so there is a conflict and nothing works. How to change default JsRender tags with custom tags, say Ruby-like <%= name %> UPD: For some reason I cannot make it work with control flow tags, for doesn't behave as expected with custom tags. Why does it happen? Here is a template: <script id="myTmpl" type="text/x-jsrender"> <%!-- This is a copmment %> <% for data %

MVVM for Web Development

我的梦境 提交于 2019-12-04 03:24:49
I've been reading up on MVVM and so far have found it very interesting. Most of the examples I've found, however, are for Windows apps, as opposed to Web apps. I've also seen a lot of mention of MVVM used with Silverlight, and I know Silverlight can be used for either Web or Windows apps. So my question is - is MVVM a valid pattern for Web-based apps? If it is, does the UI have to be Silverlight? I'm in the process of deciding which technologies to use for a new mid-size website we need to design, and Silverlight may be a hard sell to the powers-that-be, though what we use behind the scenes

Using hidden template and getting the Error 404

别等时光非礼了梦想. 提交于 2019-12-02 13:12:42
I'm new to JsViews... I used http://www.jsviews.com/#jsrplaying method to create my template. but instead of adding my template inside the I've added in the hidden . Now for the hidden template I'm getting the "NetworkError: 404 Not Found - //%7B%7B:URL%7D%7D?new={{:magicNumber}}" which is related to the URL source as it is not exist in hidden template .... {{:URL}...umber}} I'm just wondering how I can get of this error from the console (inspect element) Declaring a template in a hidden div rather than a script block is not a good idea. If the template includes things like <img src="{{:...}}"

Access parent variable from nested block in JsRender

随声附和 提交于 2019-12-02 05:48:15
问题 How can I access props 's key from a nested for ? {{props object.items}} {{:key}} {{for prop.other_items}} {{:key}} //here I want to print the key from props I've tried: {{:key}} {{:#key}} {{:#parent.key}} {{:#parent.parent.key}} {{:~root.key}} 回答1: Here are three alternative ways: Provide the key as a contextual template variable, so it is available in the {{for}} block: {{props object.items}} {{:key}} {{for prop.other_items ~outerKey=key}} Outer key: {{:~outerKey}} {{/for}} {{/props}}

How to change JsRender template tags?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 22:04:40
I use Twig. It uses these tags: {{ name }} I want to include JsRender in my project. But JsRender also uses the same tags {{:name}} , so there is a conflict and nothing works. How to change default JsRender tags with custom tags, say Ruby-like <%= name %> UPD: For some reason I cannot make it work with control flow tags, for doesn't behave as expected with custom tags. Why does it happen? Here is a template: <script id="myTmpl" type="text/x-jsrender"> <%!-- This is a copmment %> <% for data %> <%:key%> <% /for %> </script> Here is js code: var template = $.templates("#myTmpl"); var htmlOutput

JsRender. Nested loop by the object of top loop

冷暖自知 提交于 2019-11-29 15:39:20
{{for players}} <tr> {{for ~root.players}} {{if index == #index}} <td>*</td> {{else}} <td>{{index}}+{{:#getIndex()}}</td> {{/if}} {{/for}} {{/for}} I want to get access to #index of the top loop in nested loop by the players to compare top loop #index and nested loop #index. Maybe it is possible to access to top loop current item? There are several ways of getting to parent views. See http://www.jsviews.com/#views : get(type) method , Accessing "parent" data, from nested views , etc. For example you can create a contextual template parameter: ~index {{for players}} <tr> {{for ~root.players

Store a jsRender template in a separate js file

冷暖自知 提交于 2019-11-28 21:23:18
Is it possible to store a jsRender template in a separate file? I want to store it in a separate file and make a reference of it in my page. something like this <script id="templateName" type="text/x-jsrender" src="thisIsTheTemplate.js"></script> I will apreciate any commemnts or suggestions. Thanks Yes, you can accomplish this (I use this every time). let's assume that you have your templates in a template folder and it is called, for example _productDetails.tmpl.html in your page you use jQuery $.get() to pull it and load into the template, like: var renderExternalTmpl = function(item) { var