Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

widgets template system using node.js with dust server side templates

widgets template system using node.js with dust server side templates

Problem

I'm trying to create a page with Widgets on it using Node.js and Dust as a template engine. I would like the widgets to be standalone as possible with their own css, js and html.

Which of the follow three method is best? which will be the fastest?

Option a: using res.render and rendering only once

pseudo code:
   1) call page route (app.get('/', routes.somePage);
   2) load config file (say /views/somePage.cfg) listing all widgets on somePage.
   3) get widget data if needed (say access another server for the data).
   4) build 1 context object and pass to render
   5) call res.render with context containing page data + all widget's data
   5) somePage template will include partials to build page, including widget partials. 

Option b: using res.write

pseudo code:
  1) call page route (app.get('/', routes.somePage); 
  2) load config file (say /views/somePage.cfg) listing all widgets on somePage.
  3) use app.render() to render widgets + page (running js to get each widget data) 
  4) use res.write() to build a complete page.

Option c: using helpers

pseudo code:
  1) call page route (app.get('/', routes.somePage);
  2) use app.render()
  3) use custom helper to render different widgets. 
     custom helper will actually grab the data and might use app.render inside to build 
     the widget during render time..
Problem courtesy of: Dory Zidon

Solution

I went through a few things, I ended up, after discussion on Node.js IRC down the path of doing Option A...It seems it's the correct path, to build one master context and provide it to one template..

I ended up constructing a global context object, and have certain widgets add to it's json. It works like a charm!

Solution courtesy of: Dory Zidon

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

widgets template system using node.js with dust server side templates

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×