handlebars.js

How to get the result of a Meteor.call function in a template

我的未来我决定 提交于 2019-12-01 03:59:18
问题 I'm trying to make a pagination function for use in a Meteor client. Therefore I need to know the record count on the server. On the server (in server/bootstrap.coffee) I have this code: Meteor.methods ContactsCount: -> Contacts.find().count() console.log("Totalrecords: " + Contacts.find().count()) The server part is called (it displays the correct number on the console - 40) On the client I have: $.extend Template.pager, GetRecordCount: -> Meteor.call("ContactsCount", (error,result) ->

Getting the last element from a JSON array in a Handlebars template

穿精又带淫゛_ 提交于 2019-12-01 03:12:56
问题 So, I found that array elements can be accessed in Handlebars using: {{myArray.2.nestedObject}} and {{myArray.0.nestedObject}} ..to get the third and first elements for instance. (handlebars-access-array-item) Is there a way to get the last element from an array? I tried creating a helper for it: Handlebars.registerHelper("lastElement", function(array) { return array.last(); //Array.prototype extension }); ...and calling it as follows in the template: {{lastElement myArray}} or even {

inline javascript within handlebars template

不问归期 提交于 2019-12-01 03:08:41
Is there no way to have an inline script within a Handlebars template? <script type="text/x-handlebars"> I'm a row of type "foo" <script type="text/javascript">alert('hi');</script> </script> When the above template renders, the inline script is removed. What I am trying to do is include the disqus widget on a page. The widget is basically some markup + disqus script. The widget is to be included within a sub-view of my app. The subview is not visible by default but is displayed as per some logic in my Ember app code. ​ You'll have to wrap that widget in a custom Ember.View to handle

How to add a template to body in Meteor inside a package

↘锁芯ラ 提交于 2019-12-01 03:07:37
I have this template: <template name="sample"> <h1>Sample</h1> </template> Inside a Meteor app I can add this to body this way (as a partial): {{> sample}} It works. I've even tested to call Template.sample(); inside browser console and it works. When I move this inside my package (i.e. a sample.html file inside my package folder) the template seems to disappear: I get Template.sample() is not a function whenever I call the function and I am not even able to render it as a partial. I have a package.js with this code (and obviously the package is correctly loaded inside my app through packages

Example of using Handlebars lookup helper

核能气质少年 提交于 2019-12-01 02:42:50
Handlebars has a built-in helper called lookup . The documentation is not very clear about how it works. Could I see an example? Sure, past me! Here's an example from your future. Suppose you have an object or array arr and a variable key and you want to output the value of arr[key] , you would use the lookup helper {{lookup arr key}} . The code defining the helper is simply: function(obj, field) { return obj && obj[field]; } The lookup property is useful if we don't know the name of the property we want, for instance because it's in a variable or the result of an expression. If we have this

Custom for-loop helper for EmberJS/HandlebarsJS

倾然丶 夕夏残阳落幕 提交于 2019-12-01 01:59:19
A small two hours ago I started: Nested HandlebarsJS #each helpers with EmberJS not working Shortly after I figured an acceptable temporary solution myself, question is still unaswered. My problems didn't stop there though. I am now trying to make a custom helper which will loop through an array of objects, but exclude the first index - pretty much: for(i = 1; i < length; i++) {} . I've read on websites you have to get the length of your context and pass it to options - considering your function looks like: forLoop(context, options) . However, context is a string rather than an actual object.

Handlebars.js doesn't like square brackets in the front

跟風遠走 提交于 2019-12-01 01:39:23
I am using PHP-backend, Backbone.js and Handlebars.js. My javascript requests for data, and JSON data is returned successfully (json_encode). When I give this JSON data to the handlebars template, it is not displaying. I realised the square brackets in front and at the back of my JSON object are 'disliked' by Handlebars.js and not being displayed. Take a look at the code below. var ArticleListView = Backbone.View.extend( { el: $('#main'), render: function() { var template = Handlebars.compile($("#articles_hb").html()); $(this.el).html(template([{"articles":[{"title" : "1"}, {"title" : "2"}]}])

How can I dynamically insert a new template into the DOM with Ember?

放肆的年华 提交于 2019-12-01 01:38:50
问题 I have an Ember.js app. In the main template I have a help button that when clicked should display a CSS tooltip. I have the tooltip is a separate Handlebars template. What I'm trying to do is handle the click event to insert the popup into the DOM and display it. I cannot figure out how to insert new templates into the DOM using Ember. Here's my template where the help button is displayed: <div id="status_help" class="icon_help" {{action "helpClicked"}}></div> Here's my primary view: var

Loading handlebars.js template from external html file shows nothing

↘锁芯ラ 提交于 2019-12-01 00:51:29
This question is a bit of a stretch of my JS skills, so I might explain it like an idiot. Here is my JavaScript to get the json from the server, and try to push it into a template: //Server Interface Start //Access the web api for The User: var lucidServer = (function () { //global error handler $(document).ajaxError(function (event, xhr) { alert(xhr.status + " : " + xhr.statusText); }); //client Calls var getClients = function (id) { return $.ajax(clientUrl + "/list/" + id) }; var getClient = function (id) { return $.ajax(clientUrl + "/details/" + id) }; //push them out to the world! return {

inline javascript within handlebars template

落花浮王杯 提交于 2019-11-30 23:13:14
问题 Is there no way to have an inline script within a Handlebars template? <script type="text/x-handlebars"> I'm a row of type "foo" <script type="text/javascript">alert('hi');</script> </script> When the above template renders, the inline script is removed. What I am trying to do is include the disqus widget on a page. The widget is basically some markup + disqus script. The widget is to be included within a sub-view of my app. The subview is not visible by default but is displayed as per some