mustache

TypeError: this.engine is not a function when trying to use Moustache in Express JS

元气小坏坏 提交于 2019-12-11 00:49:54
问题 As the first thing I ever try on NodeJS, I'm building a simple app that displays a HTML page which tells visitors their IP address. Here's how it looks like var express = require('express'); var app = express(); app.set('view engine', 'mu2'); app.get('/', function (req, res) { res.setHeader('Content-Type', 'text/html'); // Do I have to do this? I'm not sure. res.render('frontPage.html', { ip: req.ip }); res.send(); }); app.listen(8080, function() { console.log("Listening on port 8080"); });

How to use function wrapper in mustache.php?

瘦欲@ 提交于 2019-12-11 00:08:16
问题 I'm starting to work with Mustache on PHP and I don't manage to make wrapper functions to work as debt. I have this template {{#skill_level}} <span class="stars"> {{#stars}} {{skill_level}} {{/stars}} </span> {{/skill_level}} And I have this data $data = new StdClass; $data->skill_level = 3; $data->stars = function($level) { $aux = ""; $l = intVal($level); for ($i = 0; $i < $l; $i++) { $aux .= "+"; } for ($i = $l; $i < 5; $i++) { $aux .= "."; } return $aux; }; I render m.render($tenplate,

How to use switch case in Mustache template?

只谈情不闲聊 提交于 2019-12-10 20:23:21
问题 I'm using Mustache template in Core PHP to turn PHP pages to template. Now I want to use switch case in template like: <?php switch ($gift_card['FlagStatus']) { case 'P': echo "Pending"; break; case 'A': echo "Active"; break; case 'I': echo "Inactive"; break; } ?> what should be its similar Mustache translation? thanks in advance 回答1: If you need to do more than just output a single value from the switch statement, the simplest workaround is to create a series of booleans, one for each state:

How do I add a simple onclick on a JavaScript mustache template?

非 Y 不嫁゛ 提交于 2019-12-10 17:48:40
问题 I have a simple mustache template: var template = "<button style='background: red;'>{{label}}</button>"; And the data: var data = { label: "Click me!" } Which works great with when doing the classic transformation: var html = Mustache.to_html( template, data ); But my question. How do I add a simple onclick function on my button, which I define in the indata? 回答1: Add an "onclick" atribute with code to execute as an argument. <button onclick='alert("I was called!")' style='background: red;'/>

How to use Spring Security with Mustache?

时光毁灭记忆、已成空白 提交于 2019-12-10 14:39:30
问题 I'm following the Spring Security reference, and I've got redirection to a custom login page working as described in section 3.3. However, I'm not sure how to get the CSRF token in Mustache (all the examples use JSP). I've tried a few naïve things like this... {{#_csrf}} <input type="hidden" name="{{parameterName}}" value="{{token}}"/> {{/_csrf}} ...and this... {{#CsrfToken}} <input type="hidden" name="{{parameterName}}" value="{{token}}"/> {{/CsrfToken}} ...but they don't work (and I didn't

Mustache/jQuery/javascript - how to perform method on mustache variable?

倾然丶 夕夏残阳落幕 提交于 2019-12-10 13:39:00
问题 I have a simple mustache template setup that takes an object player and creates a list element. What's the best way to perform a javascript method on a variable in mustache? Here's some sample code: var playerTemplate = '<li><span class="player-position">{{ position }}</span><span class="player-name">{{ first_name }} {{ last_name }}</span></li>'; var playerRow = Mustache.to_html(playerTemplate, player); $('ul#players-list').append(playerRow); what i'd like to do is something like: {{ position

Mustache Conditions and Loops

你离开我真会死。 提交于 2019-12-10 13:34:09
问题 Here are the resources: JSON { "badges":{ "unlocked": [ {"name": "Win 1"}, {"name": "Win 2"}, {"name": "Win 3"} ], "locked":[ {"name": "Lose 1"}, {"name": "Lose 2"}, {"name": "Lose 3"} ] } } Algorithm {{ if_has_badges }} <div class="badges"> <h1>Badges</h1> {{ if_has_badges_unlocked }} <div class="badges-unlocked"> <h2>Unlocked!</h2> {{ loop_badges_unlocked }} <a href="#" class="badge"> <strong>{{ name }}</strong> </a> {{ end_loop_badges_unlocked }} </div> {{ end_if_has_badges_unlocked }} {{

Getting TemplateSyntaxError: unexpected char u'#' on including a Mustache template in html file served by python Google App Engine

左心房为你撑大大i 提交于 2019-12-10 13:17:14
问题 I am getting a TemplateSyntaxError: unexpected char u'#' error, when I include a simple Mustache template in my HTML file being served by Python Google App Engine server. The mustache template that I want to include is: {{#item}} {{name}} {{/item}} My HTML file looks like this: <!DOCTYPE html> <html> <head> <script type="text/mustache-template" id="myTemplate"> {{#item}}{{name}}{{/item}} </script> </head> </html> Since, the template is wrapped around a script tag with type=text/mustache

Interpret html string using handlebars but escape script tags

南笙酒味 提交于 2019-12-10 13:12:22
问题 I'm bringing in a string of html for my page and I consider it html-safe except for script tags. I'm aware that triple braces will escape the html, what are the steps to leave out any script tags? Example var foo = "<h1>Foo</h1><script>some script that might possibly be in here</script><p>bar</p> then in my .hbs: {{{foo}}} I would like to see the h1 and the paragraph but have scripts left out. Thanks in advance. 回答1: You have a couple of options: Remove the script tags before passing it as

Is it possible to pass variables to a mustache partial

大城市里の小女人 提交于 2019-12-10 12:36:27
问题 Lets say I have a mustache button partial like this <button name="{{name}}" class="btn">{{title}}</button> Is it possible somehow to set the title when calling the partial directly like this <form> .... {{> button|name=foo,title=Cancel}} {{> button|name=bar,title=Submit}} </form> This would make it much easier to create views instead of something like this and creating a hash for each button. <form> .... {{#buttons}} {{> button}} {{/buttons}} </form> 回答1: I am not sure you can do that but I