FAQ Database Discussion Community


Any chance to use nested Spacebars Tags? (here: Messageformat Package, Autocomplete)

meteor,spacebars
i wond if it's anyhow possible to solve this problem with Spacebars in Meteor: {{TplVar placeholder="{{mf 'identifier' 'defaultval'}}"}} This sytnax causes a syntax error. If the placeholder would not contain spaces - as far as i know - just keeping it free of curly brackets would solve the solutions but...

Meteor: Access Template Helper (or variable) from another helper

meteor,meteor-blaze,spacebars,meteor-helper
How can I reference a template helper from another one? For example... Template.XXX.helpers({ reusableHelper: function() { return this.field1 * 25 / 100; //or some other result }, anotherHelper: function() { if (this.reusableHelper() > 300) //this does not work return this.reusableHelper() + ' is greater than 300'; else return this.reusableHelper() +...

Meteor templates #if block does not evaluate multiple optiopns

meteor,spacebars
I have an if statement which is checking for multiple roles as follows: {{#if isInRole 'User' 'Admin'}} {{> dashboard}} {{/if}} This conditional if block only checks for the first option, and does not evaluate the second one. For example, when a User logs in the dashboard template is rendered correctly,...

Meteor - Register multiple helpers at once

meteor,spacebars
In my Meteor app (v1.1.0.2) I have 10 global helpers: Template.registerHelper("getUser", function(id) { return Meteor.users.findOne({ _id: id }); }); Template.registerHelper("getPublication", function(id) { return Publications.findOne({ _id: id }); }); Template.registerHelper("getCategory", function(id) { return Categories.findOne(new Mongo.ObjectID(id)); }); Template.registerHelper("getAge", function(id) { return Ages.findOne(new Mongo.ObjectID(id)); }); Template.registerHelper("getPhoto", function(id) { return new...

return array value in a meteor spacebars template

javascript,node.js,mongodb,meteor,spacebars
I have an array of values that I want to pick the first one from in a meteor template For example <h1>{{ArrayOfTitles[0]}}</h1> It seems this can't be done like this. I don't want to have to iterate through each one, just pick the first one from the list. Any suggestions?...

How to display results from multiple databases into a list format in Meteor

javascript,mongodb,meteor,html-lists,spacebars
I've been trying to figure out how to display the list of items in two mongo collections into the same list, meaning that equivalently timestamped entries are put into the same list piece. For example: {{#each usernames}} {{> userlist}} {{/each>}} with the list template being <template name="userlist"> <li> </li> </template>...

How Do I Use a Meteor Template Helper to Edit a Value Passed as a Parameter in Iron-Router?

javascript,meteor,iron-router,spacebars
How do I use a template-helper to edit the value of the parameter I passed into a route created using the pathFor method of iron-router??? I have this template-helper: Template.registerHelper('slugify', function(obj){ return _.slugify(obj); }); in my .html file I have this: {{#each menuItemsFromDB}} {{#each arrayOfMenuItems}} <a class="item category" href=""> {{this}}...

How do I define custom template helpers in Meteor.js to format data being fed in?

javascript,meteor,spacebars
I've been trying to create a custom handle bar template helper like this: Handlebar.registerHelper('customHelper', function (originalData) { // Format the original data return formattedData; }); Here is how I would like to use it within my template: <div> {{#customHelper}} {{originalData}} {{/customHelper}} </div> i.e. there is a raw data being fed...

How to check if an object is empty in Meteor template?

javascript,meteor,handlebars.js,spacebars
I have a template data context like this: data = { "attribute1": { "attribute2": {} } } And in the meteor template I am doing something like this: {{#with attribute1}} {{#if attribute2}} show some content {{/if}} {{/with}} I don't want to show anything if attribute2 is an empty object. However...

Meteor - templates. Building simple catalogue

meteor,spacebars
I am Meteor newbie, so please, don't blame me too much for stupid question! I am fairly trying to find answer in Google and Meteor.docs, but my foolishness is stronger than me at now. I am trying to build simple Catalog of Products from two Collection. Catalogs = new Mongo.collection('catalogs');...

How to pass multiple arguments to Spacebars helper from Meteor template?

meteor,spacebars
I haven't been able to find a solid example out there. Template.registerHelper("itemLookup", function(sku, property){ return Items.findOne({sku: sku})[property]; }); How do I call this on the template? I want to do something like: {{ itemLookup sku="i3_4030U" property="title" }} It should output "Intel Core i3 4030U" ...

Where should a function be called containing Collection data from a Meteor subscription as well as jQuery DOM manipulation?

javascript,jquery,twitter-bootstrap,meteor,spacebars
I'm new to web applications and stumbled across a problem in Meteor I haven't found a good solution to (please let me know if the answer already exists on http://stackoverflow.com/). I have a profileEdit Template page I want to update with default values from the Meteor.users Collection as it is...

How to animate enter and leave of MeteorJS {{#if}} block?

animation,meteor,spacebars
The title really says it all. Given a template: {{#if selection}} <div class="something"> <p>To Animate</p> </div> {{/if}} how do I control enter and exit animations of .something? Thanks....

How to pull the data context from a view in Meteor using Blaze.getData()

javascript,meteor,meteor-blaze,spacebars
I have a select input in one of my Meteor templates which has three pieces of data associated with each select option. I am trying to send all three pieces of data (as an object) to a new template that is rendered via the Blaze API on the 'change' event...

Meteor JS: How to use Spacebars to display contents inside an array retrieved from Meteor Collection

javascript,mongodb,meteor,spacebars
I have a collection: MenuItems = new Mongo.Collection('menu_items'); and I also have an array: var arrayToInsert = ['Gemstone', 'Rings']; I then insert this array into the collection via: MenuItems.insert(arrayToInsert); The resulting document inside my mongodb as shown in RoboMongo is: { "_id" : "yRXmFGxLCZXLf9Ynh", "0" : "Gemstone", "1" : "Rings"...

Meteor JS: Inconsistency with Meteor JS when dealing with cursors?

javascript,mongodb,meteor,spacebars
I think I may have found some inconsistency within Meteor JS. Firstly this is an example of a perfectly acceptable code that doesn't cause error within Meteor JS's Template Helper: Template.admin_menu_items.helpers({ menuItems: function(){ console.log('inside menuItems'); return MenuItems.find(); }, }) However if I use Sessions to store the returned value of...

Meteor Spacebars nested tag equivalent

meteor,handlebars,spacebars,meteor-helper
I have a problem. I have a collection of documents in my database, and I would like to display each document depending on whether a session variable corresponding to that document is set. To illustrate my problem, let me give a simplified example. Meteor.myTemplate.helpers({ stuff: [ {name: 'item1'}, {name: 'item2'}...

Calling helpers before template rendered

javascript,meteor,spacebars
I am building a meteor project where I need to keep all my collections non reactive. So I have removed both subscribe and publish. To show any information from DB, my helpers are calling a method in meteor.call. But in my case, the template is not being able to show...

How to access global variables in Meteor template without using a helper?

javascript,meteor,spacebars
I have all my image files served from a different domain, and I put that host name as a variable into Meteor.settings. Then, how can I access this variable within a Meteor template? For example, in this template, what's the best practice to replace img.example.com with a variable defined in...

How can I listen to one event from two template handlers?

meteor,spacebars
For instance in the below, only the foo event handler is called. (Which is odd – I would have expected the bar event handler to be called, since the <form> element is in the bar template.) <template name="foo"> {{#bar klass="down"}} <button type="submit">test</button> {{/bar}} </template> <template name="bar"> <form> {{> Template.contentBlock}} </form>...

How can I pass parameters to an helper?

javascript,meteor,spacebars,meteor-helper
I want to pass some parameters from my HTML to my meteor helper. Can I do something like this? -> {{myHelper "customText"}} or {{myHelper context="customText"}} If so, how do I get back the string "customText"? Is it something like this? -> "myHelper": function(context){ return this.dataset[context]?"success":"danger" }, thanks!...

Passing a parameter into Meteor Template Helper

meteor,spacebars
I am trying to pass a parameter to a template helper. The parameter seems to be passed but then I can't use it as I would like to. I pass the parameter like this: {{#if unitFieldExists 'profile'}} {{profile}} {{/}} Helper in /client/lib/helpers.js Template.registerHelper('unitFieldExists', function(unitField) { var doc = Units.findOne({_id: this._id...

How Do I Properly Scope Nested #each Spacebars Iterators When Using Meteor?

javascript,meteor,spacebars
I have these nested iterators: <ul class='detailViewList'> {{#each detailsCollection}} <li id={{_id}} class='detailViewEntry {{checkboxStatus}}'> <input type="checkbox" class='detailCheckbox'> <b>{{detail}}</b> <div class="btn btn-xs btn-danger" id="delete-detail">x</div> <form class='form-inline'> <div class="form-group"> <input type="text" id='{{_id}}' name='message' class="form-control" placeholder="message"> </div> </form> {{#each messagesCollection}}...

Meteor: use dynamic parameters in a template call

validation,templates,meteor,internationalization,spacebars
In my Meteor app i have the TAPi18n package and aldeed:autoform. Im trying to make a form validation using i18n for the placeholder field but i don't know how to do it. So, I was wondering if it is possible to pass a dynamic parameter (that's how I call it)...

Meteor Helper Check equality

javascript,meteor,meteor-blaze,spacebars
Is there a way to check the value of a string in meteor helper? Lets say i have this helper Template.example.helpers({ typeOfVideo:function(videoType){ var videoLink = GS.Gems.Collections.Gems.findOne({_id:this._id}).videoLink; if(videoLink.match(/youtube\.com/)){ return "youtube"; }else if(videoLink.match(/vimeo\.com/)){ return "vimeo"; }else{ return "undefined" } } }) Now i want to check if the video is equal to...

Rendering static HTML in Meteor/Blaze

meteor,meteor-blaze,spacebars
I have been trying to include static HTML+JavaScript inside the Meteor / Telescope (telesc.pe) application, and have not been able to get things working with Blaze. To create a simpler case than my original, I have tried inserting a simple HTML + javascript code block (very basic D3.js visualization that...

Why Does {{#each}} Work Properly While {{#with}} Does Not?

javascript,meteor,spacebars
I am working on a project with Meteor.js and have some issue with the use of Handlebar : I want to retrieve the last item of a collection , and display the field : text which have html in it : here is my javascript code : Template.postVerif.helpers({ 'lastPost' :function(){...

Ternary operators in Meteor

meteor,ternary-operator,meteorite,spacebars
I am using Meteoris for working on my application. I have this scenario in forms. This is an edit view and I am just showing two of the 17 fields I have here: <label for="name" class="control-label">Name *</label> <input type="text" id="name" value="{{profile.name}}" placeholder="Name" class="form-control"> <label for="acctType" class="control-label">Account Type</label> <select id="acctType" placeholder="Name"...

How do I evaluate arbitrary expressions in a spacebars argument?

meteor,spacebars
I'd like say something like {{#if tiny || huge}}, but it looks like spacebars only takes a truthy function. What's the best solution? I thought I'd write another helper, but how do I call one helper from another helper's code? E.g. Template.foo.helpers({ tiny: function() { return this < 10 },...

How can I reverse the ordering of spacebars #each block

javascript,meteor,spacebars
A helper sentencesList is an array of objects containing an element text. HTML: {{#each sentencesList}} {{text}} {{/each}} CLIENT.JS sentencesList: function() { return Session.get(SENTENCES) } How can I reverse the ordering, i.e the highest index number is shows at the top and the element at index position 0 is at the...

What's the accepted way to render arbitrarily nested objects in a template in Meteor?

meteor,spacebars
I'm returning an object embedding other objects to arbitrary depth (representing a directory tree) from a template helper, and I'd like to render it into my template as a nested list. Since the philosophy of spacebars is to keep logic out of the template, all it offers is for loops...

Compare template helper values in Spacebars {{#if}} block

javascript,templates,meteor,meteor-blaze,spacebars
I need to compare two template helper values that are located in nested templates. I was wondering if there is an easy way to compare two template helpers (one from the parent template) in an {{#if}} statement like so: {{#each bids}} {{#if bid.price===../job.price}} <span>some text</span> {{else}} <span>some other text</span> {{/if}}...

spacebars: how to use and / or in if statements

meteor,spacebars
I have following code: <div class="form-group {{#if afFieldIsInvalid name='latitude' OR name='longitude'}}has-error{{/if}}">......</div> How can I use AND/OR in if conditions of spacebars templates ?...

How to make closable tabs with Meteor? My solution, your feedback

javascript,jquery,twitter-bootstrap,meteor,spacebars
Note: as I wrote this question, I solved it. Since I think it would be useful for both others and me to have feedback on my approach, I finished explaining the different steps. Feel free to comment/answer. Hello, I want to dynamically load/unload tabs using a dropdown for loading and...

Meteor/Spacebars Display Placeholder Text When No Documents Match User

javascript,meteor,handlebars,spacebars
I have a script that runs through a collection of photo documents, checks if they match the current user ID, and then renders the template. <ul id="settings-photos"> {{#each photos}} {{#if person}} {{> photo}} {{/if}} {{/each}} </ul> If no photos exist for a user, I would like to display a "Click...

Meteor collection - count same values

mongodb,collections,meteor,spacebars
I need to count all products in descending order and display them with spacebars. How would I do that? Result should be: book : 2 tv : 1 // My Collection Records = new Mongo.Collection('records'); // My database Records.insert({ name: "a", product: "book" }); Records.insert({ name: "b", product: "tv" });...

How to alter the display of what Spacebars outputs?

meteor,spacebars
So I have something like this in the template: {{#each posts}} <li>{{date}}</li> {{/each}} This displays fine, but the problem is that my "date" variable comes out as Sat Feb 07 2015 19:47:13 GMT-0800 (PST), which is accurate but kind of long and unneccessary. I want the date to appear simpler,...

Change column name in MariaDB

mariadb,spacebars
I have this column in this database with a spacebar included, which I want to change. ALTER TABLE . CHANGE COLUMN `Anzahl Personen` AnzahlPersonen int(11); After using this line in the command line the output is as following: ERROR 1064 (42000): You have an error in your SQL syntax; check...

Using a helper with arguments AS a helper argument in Spacebars

meteor,spacebars
So I am trying use a helper as an argument of another helper in Spacebars. In the example below, 'getResultInfo' is a helper that gets data specific to the arguments passed, and 'formatResult' is a helper that formats its result and the results of other helpers. <template name="example"> {{#each collectionResults}}...