Make BB templates available anywhere
I like having my templates live in separate files, this way I can find them all in one place and can make changes that doesn't involve digging for the embedded <script> on a given page.
If you have a build script or live resource bundler you can JSON encode them in one or many JS files as part of a global set of template objects using the functional area as the object name, with its child templates' filenames as properties, so this file structure:
Turns into this:
Once the JS resource file is added to the page, the templates are accessible simply as
window.templates.navigation.default
This allows keeping code a little more structured and maintainable.
Written by Peter Peterson
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Templates
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#