hogan.js

Typeahead templating, if/else

孤街醉人 提交于 2020-01-03 05:45:08
问题 thanks for the help on this question: Typeahead result formatting, this is a follow up. My JSON looks like [{ name="Long Island", type="2", id="1234"}, { name="New York", type="1", id="5678"}] In the drop down list I need to be able to seperate type 1 from type 2, so Type 1 heading type 1 item type 1 item* Type 2 heading type 2 item type 2 item If there are no results for type 1, then don't show the heading. Same for type 2. Is this possible with typeahead and a templating engine? I'm using

How is internationalization configured for Hogan.js?

混江龙づ霸主 提交于 2019-12-31 02:03:43
问题 I'm looking to use hogan.js to create html form a template in the browser. I've read that hogan supports i18n, but I can't find an example of how this works. How do you pass the translated text to hogan and what tag do you put in the template, I have seen both {{_i}} and {{i18n}}? 回答1: It would seem I was confusing an older fork of Mustache.js from Twitter, with Hogan a separate mustache compiler from also from twitter. The fork does support an {{_i}} tag for internationalization. This will

How to load templates with Hogan.JS from an external file?

蹲街弑〆低调 提交于 2019-12-29 11:43:01
问题 I use Hogan.JS as JavaScript templating library. It is supposed to load JavaScript templates from external files. One can probably outsource several templates in an external JavaScript file. Does anyone know how to do that? I have the following code sample: <!DOCTYPE html> <html> <head> <title>Hogan.JS Test</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script src="js/jquery-1.9.0.min.js"></script> <script src="js/hogan-2.0.0.min.js"></script> <script id=

How to load templates with Hogan.JS from an external file?

随声附和 提交于 2019-12-29 11:41:06
问题 I use Hogan.JS as JavaScript templating library. It is supposed to load JavaScript templates from external files. One can probably outsource several templates in an external JavaScript file. Does anyone know how to do that? I have the following code sample: <!DOCTYPE html> <html> <head> <title>Hogan.JS Test</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script src="js/jquery-1.9.0.min.js"></script> <script src="js/hogan-2.0.0.min.js"></script> <script id=

Laravel 4 Blade {{}} and Hogan.js {{}} Syntax

自古美人都是妖i 提交于 2019-12-22 04:42:42
问题 I am using Laravel 4 with the Blade Templating Engine and Hogan.js. By default my site thinks {{...}} is used by PHP and Laravel. Now I want to use Hogan.js and the syntax is {{...}} too. I am getting an error, because they use the same syntax here. How can I use both? 回答1: You can prepend @ to your Hogan placeholders, and Laravel will ignore them. // This will work only in JavaScript @{{ JavaScript }} // This will be rendered in blade {{ $foo }} 来源: https://stackoverflow.com/questions

Migrating to Typeahead 0.10+ with Hogan

你离开我真会死。 提交于 2019-12-18 06:48:37
问题 I have been using Typeahead 0.9.3 with Hogan 2 for a while and it was very straight forward to setup. in 0.9.3 I did something like: $('input.search-query').typeahead([ { name: "pages" ,local: localSuggestions ,template: '<div class="tt-suggest-page">{{value}}</div>' ,engine: Hogan } ]); According to the Migration Guide to 0.10 "Precompiled Templates are Now Required", so in 0.10.3 I'm trying: $('input.search-query').typeahead(null, { name: "pages" ,source: taSourceLocal.ttAdapter()

Iterate through keys/values in Hogan.js

﹥>﹥吖頭↗ 提交于 2019-12-14 04:17:00
问题 Is there a way to iterate through keys and values in an object using Hogan.js? I'm unable to find such documented functionality - only iteration over arrays seems to be documented. Is it even possible to iterate through objects in hogan.js (or any other moustache.js implementation)? 回答1: There is no way to directly iterate over the keys and values in an object in Hogan.js, what sub_stantial is doing is essentialy iterating over an array. Depending on what you want to do you need a bit of

How to get the value when using Lambda in Hogan.js

蹲街弑〆低调 提交于 2019-12-12 11:24:47
问题 I have the following function which handles AJAX success callback in jQuery: function success(data) { var templateData = { items: data, formatMoney: function () { return function (value) { return Globalization.format(value, 'N'); }; } }; // fill reports table var filledTable = tableTemplate.render(templateData); $tableContainer.html(filledTable); } Here's how my template looks like: {#Items}} <tr> <td>{{ProductId}}</td> <td>{{#formatMoney}}{{Cost}}{{/formatMoney}}</td> </tr> {{/Items}} The

Embed mustache template into another template

风格不统一 提交于 2019-12-11 16:21:36
问题 I am using Mustache for HTML templates and HoganJS as renderer. My problem is following: I have table template (table, header, body), but also I have template for each TR element of TBODY. All I want is to reuse TR-template in the TABLE-template. Whether it possible or not? Sample code: <!-- Row Template --> <script type="text/html" id="table_row_template"> <tr> <td><input type="text" name="Name" class="item-name autocomplete-groups" value="{{name}}" /></td> <td><input type="text" name="count

Hogan JS IF statements

若如初见. 提交于 2019-12-10 01:43:28
问题 I don't really like the jade syntax and was wondering if I could do this simple comparison using hoganJS instead? The example code is written in JADE. I did some googling and there seems to be mixed opinion.. I just want to know if there is a way or will I need to change something? if user li a(href='/dashboard') Dashbaord li a(href='/logout') Logout else li a(href='/login') Logi§n block body 回答1: Hogan is an implementation of Mustache so the same syntax applies. {{#user}} <li><a href="