Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expressions are lost on precompile #1232

Closed
methodbox opened this issue Jun 29, 2016 · 3 comments
Closed

Expressions are lost on precompile #1232

methodbox opened this issue Jun 29, 2016 · 3 comments

Comments

@methodbox
Copy link

methodbox commented Jun 29, 2016

I have a contact form, for example, that I can directly render expressions like this:

app.get('/contact', function(req, res) {
    res.render('contact', {test: "Test Works!"});
});

And on contact.handlebars:

<div id="contact"></div>
{{test}}

The div id="contact" is actually a precompiled template. This comes from my source, which is bundled and pulled in on the main layout html page using a simple <script src="bundle.min.js">.

Everything renders, EXCEPT any expressions defined in the precompiled template. For example:

<h1>Contact</h1>

{{> exampleForm}}

{{test}}

Test is defined in my route as described at the top. This is just for testing; eventually this data will be pulled from a database. In this example the {{> exampleForm}} is a partial that is also precompiled - just a html form - and it renders just fine, CRUD is all wired up, works fine.

Just expressions do not display unless I add them to the destination, non-precompiled template. This basically makes precompiling worthless. I want to be able to output the results of the form using a template which will display four fields, ideally populated by using something like this:

{{#if contactResults}}
  <p>{{name}}</p>
{{/if}}

But if the expression isn't preserved into the final rendered template, then the whole purpose of precompiling is worthless.

I'm sure there's a way to preserve the location of the expression without destroying it when it's precompiled. Note that NO errors are thrown in terminal or web console.

@methodbox
Copy link
Author

This appears to be an issue I've narrowed to gulp-handlebars and will likely close this issue later today.

It appears gulp-handlebars precompile either isn't compatible with handlebars 4.x or loses expressions during the compile due to evaluating them and returning an empty value (because it can't evaluate them yet).

@kpdecker
Copy link
Collaborator

Can this be closed?

@methodbox
Copy link
Author

Yes this can be closed. This is an issue with gulp-handlebars and effectively an issue with order of operations.

Writing a precompile method using "vanilla" handlebars doesn't produce the same issue.

Sorry for the late response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants