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

express running, modified template cannot be rendered rightly #22

Open
ghost opened this issue Feb 16, 2012 · 6 comments
Open

express running, modified template cannot be rendered rightly #22

ghost opened this issue Feb 16, 2012 · 6 comments

Comments

@ghost
Copy link

ghost commented Feb 16, 2012

when express server is running, I modify my template. Then access the page, the errors occurred:

500 TypeError: Cannot set property '/home/jock/apps/huodongtong/app/views/layout/form_layout.html' of undefined
at /home/jock/node_modules/jinjs/lib/environment.js:159:38
at eval at (/home/jock/node_modules/jinjs/lib/environment.js:165:14)
at Object.render (eval at (/home/jock/node_modules/jinjs/lib/environment.js:165:14))
at ServerResponse._render (/home/jock/node_modules/express/lib/view.js:425:21)
at ServerResponse.render (/home/jock/node_modules/express/lib/view.js:318:17)
at Controller.render (/home/jock/node_modules/locomotive/lib/locomotive/controller.js:98:14)

But, when I restart the server, all is right again.

what's the problem? Jinjs cached something or not?

Another question, can Jinjs can persist the compiled templates into physical files?

@ceymard
Copy link
Member

ceymard commented Mar 13, 2012

Can you give me a reliable way of reproducing the error ?

There is indeed probably a caching problem.

@kidrecursive
Copy link

Here is how to recreate the issue, he is using Locomotive, so perhaps that is the easiest way, from the command line run:

npm install locomotive -g
lcm create hello
cd hello
npm install
npm install jinjs

Then, change /config/environments/all.js to:

var express = require('express');

module.exports = function() {
    this.set('views', __dirname + '/../../app/views');
    this.set('view engine', 'jinjs');
    this.set('view options', {
        layout: false
    });
    this.use(express.logger());
    this.use(express.bodyParser());
    this.use(this.router);
    this.use(express.static(__dirname + '/../../public'));
};

Then, add 'base.html.jinjs' to '/app/views' with this in the file:

<!DOCTYPE html>
<html>
  <head>
    <title>Hello</title>
  </head>
  <body>
    {% block content %}
    {% endblock %}
  </body>
</html>

Then, add 'main.html.jinjs' to '/app/views/pages' with this in the file:

{% extends "base.html.jinjs" %}

{% block content %}
    <h1>{{ title }}</h1>
{% endblock %}

Now, start the app from the command line with:

lcm server

Then, open your browser to 'http://127.0.0.1:3000'. The first load will work, then refresh the page, after 2-5 refreshes, you will see the error described above. Below is the offending line, deps is the undefined property in environment.js:

_this.deps[__filename][path] = true;

@Zizzamia
Copy link

Zizzamia commented Apr 1, 2012

I have the same problem and for now I have solved with this solution, but I'm not certainly is the best solution.

The solution is this page Zizzamia/zizzamia.com@688bfa7#diff-2 .

Let me know if you find a good way. :-)

@nmcclay
Copy link

nmcclay commented May 28, 2012

I had the same issue, and I can confirm Zizzamia's fix for environment.js seems to resolve it:

// Solved the problem for now, but I'm certainly not the best solution.
try {
    _this.deps[__filename][path] = true;
    return _this.getTemplate(path);
} catch (err){
    return _this.getTemplate(path);
}

Importing 'pwilang' didn't seem to make a difference as far as I can tell. Just needs the above fix to jinjs/lib/environment.js around line 160.

@Zizzamia
Copy link

Nice... I'm not alone in this issue :-D

@kconragan
Copy link

I'm also having the same problem and Zizzamia's patch corrects it. Thanks!

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

5 participants