Skip to main content

Posts tagged with 'javascript'

Welcome to another "Weekly Concerns". This is a post-a-week series of interesting links, relevant to programming and programmers. You can check out previous Weekly Concerns posts in the archive.

If you have an interesting link that you'd like to see in Weekly Concerns, leave a comment or contact me.

A project I'm working on now has a SPA project that uses the doT template engine.

Using it isn't terribly different from other JS templating engines (like Mustache), so if you have experience with those, it should look pretty similar.

First, you need a template. Just define it in a <script></script> block like so:

Notice the {{ }} areas in the template? That's what doT is going to fill in with whatever data we want (i.e. interpolation). The data that will be passed in is simply a JavaScript object, and this template knows that object by the name "it". So you can think of "it" as kinda like a keyword.

The next step would be to get the data, get the template, and combine them together to get an output.

Note that I'm using jQuery for convenience, but it's not required.

doT demo in Chrome

doT also offers conditionals and looping. It claims to be the "fastest + concise" templating engine for Node.js and browsers. If performance is a major concern for your templating engine, you can check out their benchmarks. Seems to be a close race depending on the browser, but doT is no slouch. Personally, I believe that templating is (hopefully) such a small part of the overall performance of a typical SPA app that it won't keep me up at night.

Welcome to another "Weekly Concerns". This is a post-a-week series of interesting links, relevant to programming and programmers. You can check out previous Weekly Concerns posts in the archive.

  • Need a real API for demonstrating Ajax stuff? Check out The Example API. It provides all kinds of methods (GET, POST, etc), content responses (JSON, JSONP, XML, etc), response codes (404, 500, etc). Great for cross-domain testing, and it's what I used for my jsonp example post.
  • Something to think about: Why Link Shorteners Harm Your Readers
  • How to create better cards (in Pivotal, LeanKit, whatever card tracking/PM system you're using). I find the idea of gherkin/cucumber tests in the card to be an intriguing one.
  • Need a dummy placeholder image? Use dummyimage.com to get them dynamically.

Ever experience the new wave? Next wave? Dream wave? Flava flav? A guy named Dave? Men's aftershave? A voodoo conclave? 12 Years a Slave? Shortwave? OR CYBERPUNK!? Ever stared at a CRT wistfully?

I didn't think so.

If you have an interesting link that you'd like to see in Weekly Concerns, leave a comment or contact me.

Welcome to another "Weekly Concerns". This is a post-a-week series of interesting links, relevant to programming and programmers. You can check out previous Weekly Concerns posts in the archive.

If you have an interesting link that you'd like to see in Weekly Concerns, leave a comment or contact me.

Welcome to another "Weekly Concerns". This is a post-a-week series of interesting links, relevant to programming and programmers. You can check out previous Weekly Concerns posts in the archive.

If you have an interesting link that you'd like to see in Weekly Concerns, leave a comment or contact me.

Matthew D. Groves

About the Author

Matthew D. Groves lives in Central Ohio. He works remotely, loves to code, and is a Microsoft MVP.

Latest Comments

Twitter