I'm using Grunt and Assemble to create precompiled templates on my site but I need to dynamically create some sections based on information stored in client-side storage. Is there a way to exempt sections of a template from precompilation?
Mixing dynamic/precompiled handlebar templates using assemble
2k Views Asked by Indolering At
1
There are 1 best solutions below
Related Questions in HANDLEBARS.JS
- Handlebars or ember blocking href to external url
- Express 4.0 Failed to Look up view in "/views" directory
- Inserting template code below code in Handlebars layout.hbs
- Backbone Collection only fetched after executing alert
- Installing handlebars without npm
- handlebars include partial in index
- Handlebars template won't render ember data object
- How to get a parent element from an each in meteor?
- Accessing handlebars variable via javascript
- mandrill template variables not substituting
- The refreshed AJAX content hidden due to a CSS property
- Access Properties of JS Object on Controller
- Handlebars template not rendering as expected
- Using compiled images inside Handlebars erb templates
- Referencing handlebars variable in a loop
Related Questions in ASSEMBLE
- Passing HTML in JSON as data in Assemble
- How to loop partials in Assemble
- How to Register custom handelbars helper in assemble 0.17.1
- Different foot block per page
- Parsing json data in to Assemble 0.17.1 via Gulp
- Assemble, Handlebars partial, YAML Front matter
- How do I assemble on github page instead of jekyll
- Assemble page with multiple named sections
- Grunt assemble - strange 'module not found' issue
- Matching of data files to pages
- How to provide a link to the 'next post'
- grunt assemble error _config.yml file not generated?
- How to include var in partials calls
- Correct way to import custom handlebar helpers to assemble
- How to use a handlebars #each helper with YAML front matter
Related Questions in GRUNT-ASSEMBLE
- grunt assemble error _config.yml file not generated?
- How to prefix file names when using grunt assemble
- grunt assemble multiple files from one datafile
- Get first item in a sorted collection
- Yeoman Webapp in combination with Assemble
- Assemble (templates): Get parent value from within nested each block
- Register Assemble Handlebars Helpers
- How to use assemble-middleware-i18n?
- Assemble: register handlebar helper function
- How to include different content partials with Assemble based on dev/build context?
- Get current url query string
- How to use custom option form grunt task in loops
- How to use parameter in assemble partial
- How can I use a collection list outside its parent in another collection in assemble?
- Looping through subdirectories in yeoman and assemble
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
We can't do custom delimiters (a shortcoming of Handlebars), but there are a couple of solutions that might work for you. Neither is necessarily idiomatic, so you be the judge of how suitable these are for the project you're working on.
string replacement
You could use some custom (temporary) delimiters for the templates in the content that shouldn't be compiled, then create a block helper that will convert those delimiters back to valid handlebars expressions during compile time (I tested this for this answer and it works):
For example:
Then use it like this:
Inside
foo.hbs, you might have something like this:and it will render to:
This solution is hacky for sure, and you might have problems if you happen have any code examples embedded in the included content and one of the examples happens to have that syntax (like
[0,1,[foo, bar]].escaping
This solution is most likely the better way to go. Handlebars will not evaluate any templates that are preceded by
\. So you can do this:and it will render to:
The first suggestion probably wasn't even worth adding, but hey, you never know right?