Re: Express and Hogan.js Partials

2,894 views
Skip to first unread message

Felix Weiss

unread,
Sep 26, 2012, 1:06:45 PM9/26/12
to expre...@googlegroups.com
I got this solution:

index.hjs
<html>
  <head>
    <title>{{ title }}</title>
  </head>
  <body>
    <!-- body: res.render -->
  </body>
</html>

about.hjs
<h1>{{ headline }}</h1>
<p>Welcome to {{ name }}</p>

router.js
    app.get('/', function(req, res) {
       res.render('index', {
            title: 'Nested Templates',
            body: res.render('about', {
                headline: 'About Hogan.js in Express',
                name: 'Node.js'
            })
        });
    });



Am Sonntag, 2. September 2012 02:52:39 UTC+2 schrieb Felix Weiss:
It' great, we can generate an app with Hogan.js support, because Hogan.js is really fast an usually partials are possible. So my question: How can we use partials with Express? Or is this feature still disabled in Express? I tried to get it working, but somehow it doesn't. :-/

I would appreciate your hint! :-)

layout.hjs
<!DOCTYPE html>
<html>
  <head>
    <title>{{ title }}</title>
    <link rel='stylesheet' href='/stylesheets/style.css' />
  </head>
  <body>
    {{> about }}
  </body>
</html>

about.hjs
<h1>{{ title }}</h1>
<p>Welcome to {{ name }}</p> 

 

Felix Weiss

unread,
Sep 26, 2012, 1:57:00 PM9/26/12
to expre...@googlegroups.com
But I just realized, that all stylesheets will be ignored. :-/

Felix Weiss

unread,
Sep 26, 2012, 2:02:16 PM9/26/12
to expre...@googlegroups.com
Another possible solution:

index.hjs
<!DOCTYPE html>
<html>
  <head>
    <title>{{ title }}</title>
  </head>
  <body>
    {{ about }}
  </body>
</html>

router.js
    var about = fs.readFileSync('about.hjs', 'utf-8');

    app.get('/', function(req, res) {
       res.render('index', {
            title: 'Nested Templates',
            about: about
        });
    });

James Long

unread,
Sep 27, 2012, 9:41:10 AM9/27/12
to expre...@googlegroups.com
If you keep having a lot of problems with this, it might be worth
checking out a different templating engine. I wrote nunjucks, a port
of jinja2, because I was having these kinds of problems over and over.

http://nunjucks.jlongster.com/

All you have to do is:

{% include "about.html" %}

- James
> --
> You received this message because you are subscribed to the Google Groups
> "Express" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/express-js/-/iJHPIi90OLUJ.
>
> To post to this group, send email to expre...@googlegroups.com.
> To unsubscribe from this group, send email to
> express-js+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/express-js?hl=en.

tjholowaychuk

unread,
Sep 27, 2012, 11:43:49 AM9/27/12
to Express
this is just the nature of hogan... most mustaches do not perform any
IO, thus
you can't really use layouts or partials unless you load them in first
Reply all
Reply to author
Forward
0 new messages