Create a Docpad app which rendered its views using Handlebar templates so that the same templates could be shared by a frontend JS app.
- Clone the repo
git clone https://github.com/100Shapes/docpad-handlebars.git
- Install the dependencies
cd docpad-handlebars && npm install
- Run the app
docpad run
- Launch the app
- Note the line of text
- Turn JavaScript off in the browser and refresh
- Docpad renders the same template
Due to the Docpad-plugin-Handlebars, we're actually precompiling the Handlebars templates for the browser.
- The
Home
document is a normal Docpad Document, but it calls a template function to generate its view rather than doing it itself - The templates referred to by name, with a simple data object just like any other rendering any other Handlebars template
- Here we take advantage of the Docpad Handlebars plugin and point requirejs at the precompiled Handlebars templates
- Write the view to render the template
- Finally, call that view from within the page (here, we're cheating slightly by using the
layout
)
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.