Questions tagged [hogan.js]

Hogan.js is a JavaScript templating engine for Mustache templates.

Hogan is a JavaScript library that parses and compiles Mustache templates. It can run in both the web browser and other JavaScript engines such as Node.js and Rhino.

Example usage

Hogan uses standard mustache templates:

<script type="text/html" id="topUsersTemplate">
    <h1>{{title}}</h1>
    <ul>
        {{#users}}
            <li>{{name}} ({{postCount}})</li>
        {{/users}}
    </ul>
</script>

These can then be compiled on the client:

var template = Hogan.compile(document.getElementById("topUsersTemplate").innerHTML);

Or pre-compiled on the server and delivered as pure JavaScript code, which can just be included with a script tag. This is preferable as compilation is the most expensive operation:

<script src="/js/topUsersTemplate.js"></script>

The template is then rendered with a context object which contains the fields to expand the template.

var context = {
    "title": "Top Users",
    "users": [
        {
            "name": "User 1",
            "postCount": 2000
        },
        {
            "name": "User 2",
            "postCount": 1900
        },
        {
            "name": "User 3",
            "postCount": 1800
        }
    ]
};

document.body.innerHTML = template.render(context);

The preceding code would produce:

<h1>Top Users</h1>
<ul>
    <li>User 1 (2000)</li>
    <li>User 2 (1900)</li>
    <li>User 3 (1800)</li>
</ul>
139 questions
18
votes
6 answers

Partials with Node.js + Express + Hogan.js

I'm developing a site with Node.js + Express and using as view engine Hogan.js. This is my file app.js: /** * Module dependencies. */ var express = require('express') , routes = require('./routes') , user = require('./routes/user') , http =…
user1288707
15
votes
0 answers

Is hogan.js unmaintained? Is it safe to use?

I've seen that Twitter's hogan.js is not making progress and it's somewhat abandoned (github: https://github.com/twitter/hogan.js). The issues are not being attended, and last version in NPM is 2.0.0 (https://www.npmjs.org/package/hogan.js), while…
Eneko
  • 501
  • 4
  • 15
13
votes
1 answer

Hogan JS IF statements

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…
user61026
  • 285
  • 2
  • 13
9
votes
2 answers

How to handle string or array of strings in mustache template

I have a simple/beginner question for using mustache templating in my app (or Hogan more accurately). I am using an API which sometimes returns a String and sometimes returns an Array of Strings. I know could wrap the String in a single-element…
lmsurprenant
  • 1,723
  • 2
  • 14
  • 28
9
votes
3 answers

Express 3.x best layout implementation (template engines)

From what I've read, ExpressJS 3, dropped support of layouts, leaving it to the template engines. So if an engine, doesn't have a support for layouts, what's the best Node.js module that will have it? Or if best sounds subjective, not best but at…
C-Blu
  • 103
  • 1
  • 1
  • 5
9
votes
3 answers

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

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…
Benny Code
  • 51,456
  • 28
  • 233
  • 198
7
votes
1 answer

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

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.…
zer02
  • 3,963
  • 4
  • 31
  • 66
7
votes
2 answers

hogan.js with master pages or layouts

Is it possible in any way to use hogan.js as template engine with layouts something like "Razor or master pages in .NET"? I would get a result like this: layout.hjs: contains "header" & "footer" and index.hjs: will include layout.hjs and contain…
paul.g
  • 181
  • 1
  • 9
7
votes
1 answer

Which hogan.js templeting package to use with express.js?

The hogan.js template package that express provide is hjs, however, that package last update was a year ago, and the repo at github got issues opened also a year ago (though not really crucial ones). There also seems to be more than one hogan.js…
Ansd
  • 1,865
  • 3
  • 19
  • 30
7
votes
3 answers

Twitter typeahead.js: Possible to use Angular JS as template engine? If not how do I replace "{{}}" for Hogan/Mustache js?

I am working with twitter's typeahead.js and I was wondering if it was possible to modify hogan.js to use something other than {{}}? I am looking at the minified code now and I have no idea what to change for something so simple. Doing a find and…
meiryo
  • 11,157
  • 14
  • 47
  • 52
6
votes
2 answers

How to have helpers in Hogan.js

I am planning to use Hogan.js for my next project. I was trying to experiment with it a bit. I am just stuck and unable to find out how to use helpers with Hogan.js. I used to use to with Handlebars earlier. Is there a way to have a similar thing on…
Goje87
  • 2,839
  • 7
  • 28
  • 48
5
votes
1 answer

Migrating to Typeahead 0.10+ with Hogan

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 …
isapir
  • 21,295
  • 13
  • 115
  • 116
5
votes
1 answer

How to handle pluralization in Hogan

I'm using Hogan.js, which is compatible with the Mustache spec. And im having trouble implementing a solid way of doing pluralization. I would like to keep using Hogan and use http://i18next.com/ for i18n handling doing something like this works for…
Paul Scheltema
  • 1,993
  • 15
  • 25
5
votes
1 answer

Require with Hogan and how to render html entity from JSON

I am using Hogan js for my template and require js as a module loader. Have the necessary libraries such as jquery js, hogan js, require js in place. index.html is below
radiant
  • 142
  • 2
  • 9
4
votes
3 answers

Mustache-like templating language with extends?

I like the minimal-ness of mustache-style templating languages - I'm currently using mustache and icanhasmustache, but I've also checked out handlebars and hogan. However I have a need to for an 'extends' type functionality, to allow a child to…
mikemaccana
  • 110,530
  • 99
  • 389
  • 494
1
2 3
9 10