mustache

How to dynamically load partials in Mustache PHP?

痞子三分冷 提交于 2019-12-13 01:33:55
问题 I'm having trouble finding decent docs on loading partials programmatically through Mustache. I'm trying to load a login page with the form being a partial (it'll change depending on different user interactions). PHP: $m = new Mustache_Engine(array( 'loader' => new Mustache_Loader_FilesystemLoader(dirname(__FILE__) . '/views'), 'partials_loader' => new Mustache_Loader_FilesystemLoader(dirname(__FILE__) . '/views/login/partials') )); $params = array(); $partials = array( 'login_area' => 'login

javascript and mustache - passing an array to template

若如初见. 提交于 2019-12-12 16:32:38
问题 I am trying to learn mustache / icanhaz in conjunction with jquery and javascript, and I've got a mustache template to which I'm passing various data. One of the pieces of data is a list of choices, but that list can vary in length (say, one to three choices). How do I pass that varying data to mustache? This is my code: Javascript: for (childIndex in scenes[sceneID].children) { childSceneID = scenes[sceneID].children[childIndex]; childScene = scenes[childSceneID]; childLink = childScene.name

Mustache render on the server (rails) and on the client (javascript)

被刻印的时光 ゝ 提交于 2019-12-12 11:34:57
问题 Is there any documentation on Mustache best practices when using on the server (with rails) and on the client (with javascript)? # hello_world.mustache Hello {{planet}} # some other file <% hello_world_template = File.read(File.dirname(__FILE__) + "/hello_world.mustache") %> <script id="hello_world_template" type="text/x-jquery-tmpl"> <%= hello_world_template %> </script> <script> // $.mustache = using mustache.js and a jquery mustache wrapper // search on "Shameless port of a shameless port"

Escape Mustache variable containing apostrophe for JavaScript

本秂侑毒 提交于 2019-12-12 10:40:01
问题 I have a variable ( {{title}} ) which contains an apostrophe. Mustache escapes this as ' . However, the following template results in a JavaScript error ( Expected token ')' ): <a href="javascript:confirm('{{title}}?');">{{title}}</a> After Mustache rendering, the syntax error is clear ( 'Joe's Lame?' ): <a href="javascript:confirm('Joe's Lame?');">Joe's Lame</a> I am still learning Mustache and while this example is contrived, what is the proper way to escape variables in these situations.

Mustache inside of href

倖福魔咒の 提交于 2019-12-12 07:48:18
问题 I have JSON like this: { "something": "http://something.com" } and HTML like this: <a href="{{something}}">{{something}}</a> When I apply Mustache, I get <a href="%7B%7Bsomething%7D%7D">http://something.com</a> But what I am trying to get is <a href="http://something.com">http://something.com</a> I already tried {{{ something}}} , {{& something}} , single quotes, double quotes... I even read documentation. Can you help me? 回答1: Make sure your template source is straight text - don't try and

Handlebars.JS (w/ Dashbars) parse error “expecting open_endblock got inverse”

限于喜欢 提交于 2019-12-12 06:13:56
问题 First, I dumped the output that's going to the Handlebars template and ran it through JSONlint.com and it validates, so my inputs are valid. Second, this is the best example code I could cook up that's representative but doesn't include vital data: http://codepen.io/Muzical84/pen/BNBLom?editors=101 (note, if you have HTTPS-Everywhere on, turn it off on codepen.io since the support is listed as "partial," and Chrome might still bark about unsafe scripts; I included all of the libraries besides

Why does this function not work inside of an object but basically the same function outside of an object will work?

走远了吗. 提交于 2019-12-12 06:04:28
问题 I am new to mustache and have reached a problem i am clueless to why it's their. I am trying to inject my page with a template using Mustache. The problem is that my function to grab and inject the template in the DOM works outside of an object but will not work inside of one. Please any help to shine some light on this situatino would be great. Code that works(OUTSIDE OF OBJECT): var portfolio = { projects: { "proj": [ { id:"1", title:"Heller Recipes", description:"This web applications was

Having Mustache templates both render and not, with Laravel/Blade and JavaScript

橙三吉。 提交于 2019-12-12 03:22:21
问题 I'm using Laravel and all my templates are using Blade templating. There are a few parts of pages which need to be rendered both on the server side and by JavaScript. For these I'm using Mustache templates (with mustache-l4). The problem is how to have Laravel render the templates, but also to include them in the page with the Mustache tags intact, for the JS to pick up. For example, if I have a (simplified example) Blade template like this: <html> <head></head> <body> <h1>{{ $pageTitle }}<

Set attributes in haml using variable in mustache

家住魔仙堡 提交于 2019-12-12 03:15:55
问题 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? 回答1: You could use :plain , something like this: :plain <div class="module-subtitle" title="{{title}}"> {{title}} </div> 回答2: Without seeing more of your code and running some

Switch case in MustacheJs

孤街醉人 提交于 2019-12-12 01:32:51
问题 Using Mustache js (a logic less templating) is there a way i can achieve switch case? this i need because a class is assigned to dom element based on the value for example: switch(tasks.Count) { case 0: element.Class = "no-tasks"; break; case 1: element.Class = "one-tasks"; break; . . . } that's the code i got now, how do i transform it to template( I Believe having methods on model being rendered is the one option) But adding methods to determine which class to use is an overkill and besides