Skip to content

Example of a Docpad app which renders its views using Handlebars templates which are shared by a JS application

Notifications You must be signed in to change notification settings

100Shapes/docpad-handlebars

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docpad-Handlebars

Objective

Create a Docpad app which rendered its views using Handlebar templates so that the same templates could be shared by a frontend JS app.

Getting setup

  1. Clone the repo git clone https://github.com/100Shapes/docpad-handlebars.git
  2. Install the dependencies cd docpad-handlebars && npm install
  3. Run the app docpad run

Running the app

  1. Launch the app
  2. Note the line of text
  3. Turn JavaScript off in the browser and refresh
  4. Docpad renders the same template

Special Sauce

Due to the Docpad-plugin-Handlebars, we're actually precompiling the Handlebars templates for the browser.

How does it work?

The Docpad side

  1. The Home document is a normal Docpad Document, but it calls a template function to generate its view rather than doing it itself
  2. The templates referred to by name, with a simple data object just like any other rendering any other Handlebars template

The JS side

  1. Here we take advantage of the Docpad Handlebars plugin and point requirejs at the precompiled Handlebars templates
  2. Write the view to render the template
  3. Finally, call that view from within the page (here, we're cheating slightly by using the layout)

License

The MIT License (MIT)

Copyright (c) 2013 ONEHUDNREDSHAPES LTD.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Example of a Docpad app which renders its views using Handlebars templates which are shared by a JS application

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published