FAQ Database Discussion Community


How do I compile mustache templates partials with gulp?

gulp,mustache
I make prototypes of static HTML pages with Mustache/Sass/Compass-watch under Ruby. This setup is VERY slow, so I want to move to building everything with Gulp. I managed to have it build Sass, but not Mustache. It just doesn't see partials in mustache templates. My file structure is like this:...

Button in table fires both button and table event when clicked

javascript,jquery,html,mustache
I have a table that displays info on certain components and at the right side of the table, I have a delete button. As of now, I have it so when clicking on a component's row it brings you to a new page. Since my delete button is also on...

select the element not equal `#text`

javascript,jquery,dom,mustache
After use mustache render I try to get the dom just append, how do I select only li.data? or How to make mustache return appendedDom not include #text? .. var html = Mustache.to_html(this.template.data, response); var appendedDom = $(html).appendTo(this.el.container); console.log(appendedDom); >> console.log <li class=​"data">​…​</li>​ #text I tried $(appendedDom+'.data') this not work...

how do I omit a line when field is empty (using mustache/handlebars)

javascript,handlebars.js,mustache
i'm currently using mustache and trying to implement some basic if-else checking. In my case, I'm checking for a value in a field. for example: I have this JSON data: "AGENCIES":[ { "IASTATE":"Buenos Aires", "IAADDRESS1":"Paraguay 647 Piso 4 Of. 17\/18", "IAADDRESS3":"", "IALEGALNAME":"Silvia Stocker Australia & New Zealand Travel (ANZ Group)",...

Why does $.each show only one of my Mustache templates?

javascript,jquery,each,mustache
I'm using $.get inside $.each to call an external Mustache template to use on each Photo object in my array. Here is my code: $.when.apply($, requests).then(function(dataOne, dataTwo) { $.each(dataOne, function(idx, obj) { $.get("myTemplate.mst", function(template) { var rendered = Mustache.render(template, obj); $photoElem.html(rendered); }); }); }); My problem is that once I...

How to access elements rendered into the page with Mustache using jQuery

javascript,jquery,ajax,mustache
I am rendering some content into my page using a mustache template and ajax. I would then like to interact with some of the elements (hide them depending on page position) using another function (componentLoaded). Obviously this function needs to run after the items are rendered on the page, but...

mustache.js is not working

javascript,mustache
I am trying to learn mustache js but the basic page does not work. I was following the http://iviewsource.com/codingtutorials/introduction-to-javascript-templating-with-mustache-js/ but it is out of the date. (Currently the basic html doesn't work. In the future I would like to use get JSON in script to get data from json files.)...

How to reference a variable outside the current block variable?

javascript,handlebars.js,mustache,handlebars
Say I have two arrays in a structure I'm passing to my template: { days: 'Mon,Tue,Wed,Thu,Fri'.split(','), times: 'Morning,Afternoon,Night'.split(',') } I want to list each day, and for each day, list each time. However, when I reference the times array inside a loop over the days array, it seems to think...

Traversing to a parent in Ractivejs mustache

javascript,mustache,ractivejs
I'm trying to get an object above a loop so I can grab it for a function but I get undefined when trying to do ../../this which I thought you could do after looking at the docs. My code currently looks like this: {{#each locations}} <input type="text" name="location[]" value="{{location}}"> <ul>...

mustache js fail to load view as an array from json file

javascript,jquery,json,mustache
I am trying to load my data from my JSON file but apparently only the first attribute was loaded. I created an array by using jQuery push method to extract the data from my JSON file. When I see the array output from console.log, it looks fine. I don't get...

Can I limit Mustache to the current scope?

mustache
Is there a way in Mustache to refer to the current scope only? { "name": "name1", "list": [ { "name": "name2", "value": 200 }, { "value": 300 } ] } Output: name2: 200 name1: 300 Since it searches ancestor scopes. But what I need is: name2: 200 300 Is there...

How to loop through an Json array in mustache template

jquery,mustache
I have an array with JSON object: {result" : "OK","data":[ {"name" : "henrytest", "id" : "9a3d1faaaac742889a940a6d9df49d16"}, {"name" : "henrytest", "id" : "9a3d1faaaac742889a940a6d9df49d16"}, {"name" : "henrytest", "id" : "9a3d1faaaac742889a940a6d9df49d16"} ] } I'm trying to loop through the array to get the 3 fields displayed in my table. However nothing is getting...

Hard pro coding - strange error in IE8

javascript,html,internet-explorer-8,mustache,template-engine
Please help to find an error in library to compile HTML. Unfortunately it won't work with <script type="text/template"></script> for IE. "Unterminated string constant" appears in IE8 console in line with this code: return new Function("variables", 'variables = [variables], svar = "' + block(template.replace(/"/g, '\\"').replace(/\n/g, '\\n')) + '"; return svar;'); Full...

For loop in Hogan JS template

javascript,for-loop,express,mustache,hogan.js
I am using Express JS and Hogan JS template engine. I know hogan is logic less template but I need to execute a for loop in view code to generate table fields. I have done lots of googling but I did not found any solution. I know how to do...

Set attributes in haml using variable in mustache

ruby,haml,mustache
I'm using both haml and mustache for frontend. There is a code snippet: .module-subtitle {{title}} I want to show a tooltip for .module-subtitle with title attribute, using the content inside {{title}}. I tried .module-subtitle{ :"title" => {{title}}} {{title}} but it didn't work as it has syntax error. Any hints?...

Persistent templates (or re-using templates) with Hogan / Mustache?

javascript,templates,mustache,hogan.js
Not entirely sure if "persistent templates" is what I am after, this is the first time I am using a Javascript templating engine. I am curious if there is a way of keeping the template data intact for the purposes of re-rendering a document once it has been rendered... An...

Escape variable name with Mustache.js

javascript,mustache
I have a csv file that I'm parsing to JSON and then sending to Mustache.js. The problem is that some of the variable names are not well formed, so I end up with objects that may look like this: { 'Num.': '1234', 'Pass-through': 'yes' } So how would I use...

Mustache Dynamically set variable

javascript,mustache
I need help in using a javascript variable set dynamically as my mustache template variable. Here is the problem. My JSON looks like this jsonData = { "recipemodules" : { "enchiladas" : [ { "title" : "Chicken Enchiladas", "thumbnailurl" : "http:www.google.com/image", "recipelink" : "location to recipe", "credit" : "some credit"...

unexplained undefined string displayed on my website. not sure how to get rid of it

javascript,mustache
I have a undefined string being displayed on my page and i have no idea why it is their besides the function that is probably causing it, i only know this from displaying allot of console errors to locate the problem. I believe that Mustache is doing this somehow when...

If clause in haml using variable from mustache

ruby,haml,mustache
Similar to this question, I want to use if clause in haml file, specifically only display the image when there is actually image url. The code is %div{ :class => "attachment {{ attachment_type }}" } %a{ :href => "{{ attachment_url }}", :target=> "_blank"} %img.image{ :src => "{{ attachment_pic_url } and...

Symfony2 Service reference from mustache

php,symfony2,mustache
i have a mustache template that has the following line {{{widgets.service_name.js.footer}}} i found the corresponding service defined in a symfony2 bundle service_name: class: A\B\C\D\EventListener\AssetsListener arguments: - @templating - %a.b.timestamp% - %kernel.environment% tags: - { name: kernel.event_listener, event: kernel.response, method: injectAsset, priority: -255} Is there a mustache specific meaning in .js.footer...

looping through two dimensional array and passing to mustache template

php,arrays,mustache,mustache.php
so I am just getting started using mustache.php and I am stuck trying to loop though a two dimensional array. I have an array that looks like this... $FeedArray = array(3) { [0]=> array(3) { ["entity"]=> string(10) "mail" ["time"]=> string(19) "2015-02-05 05:10:26" ["title"]=> string(0) "what's up?" } [1]=> array(3) {...

Mustache Render Ignoring all {{ }}

jquery,mustache
I'm using the following basic introduction example from here: https://github.com/janl/mustache.js/ I'm using the following code: var tmp_view = { title: "Joe", calc: function(){ return 2+5; } }; var tmp_output = Mustache.render("{{title}} spends {{calc}}", tmp_view); However, in my browser all I'm getting is: var tmp_output = Mustache.render(" spends ", tmp_view); Which...

Display first object in object array using mustache

jquery,templates,mustache
I am new to Mustache and trying to figure out how to display the first object array in a list using mustache. I woulld like to be able to to pass a varialbe to decide which index of the list will be displayed using the mustache template. for example: var...

Mustache: only show if key has non-false value

mustache,handlebars
In a Mustache template, how can I show a block containing a value only when said value is a non-false value? I need to be able to show or not show an entire block, not just the value. For example, in Handlebars: {{#if name}} Hi {{name}}! {{/if}} But in Mustache,...

How to get mustache html in java

java,mustache
I'm trying to use mustache to fill an html for me, then i want to get that html and use it as String. A template like this -> template.xhtml <table style="width:10%" align="center"> <tr> <th>Old</th> <th>New</th> </tr> <tr> <td>{{old}}</td> <td>{{new}}</td> </tr> </table> With a Hash like this: HashMap<String, String> scopes =...

How to render array into specific form for mustache to render

javascript,html,underscore.js,mustache
I get an array of objects with image locations via API and I can't manage to render it. I managed to get my array into chuncks of 4 using underscore, but I can't get my head around how to massage my data into correct form so I could render it...

Conflict between masonryjs and mustachejs

javascript,mustache,jquery-masonry
I have a syntax error somewhere in my javascript that seems to be slipping by. I can either access the content through a file into a mustache template, or I can hard code the items (images and audio) and have the items smoothly fill up the page with masonryjs. But...

mustache {{{partial}}} vs {{> partial}}

handlebars.js,mustache,handlebars
I have a handlebars/mustache layout file in my node.js application that looks like this: {{> header}} {{> navbar}} {{{body}}} {{> footer-user}} {{> footer}} Since all five lines are includes, is there any difference between the two types of includes? Could I replace {{{body}}} with {{>body}} or {{> header}} with {{{header}}}?...