K
K
Keenest2012-08-09 14:34:52
Node.js
Keenest, 2012-08-09 14:34:52

Dzhang-like templating engine or how to fix swig?

Good afternoon.
Upgrading node.js from 0.7.9 to 0.8.6 did not go unnoticed — in addition to a couple of deprecated functions, express had an error when configuring the django-like templating engine swig :
TypeError: Object function app(req, res){ app.handle(req , res); } has no method 'register'

app.register('.html', swig);<br>
app.set('views', VIEWS_PATH);<br>
app.set('view engine', 'html');<br>

I would be glad to know the solution to the problem with swig, or hear the names of similar proven template engines. Thank you.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
K
Keenest, 2012-08-09
@Keenest

So. The source of the problems is express.js updated from 2.5.0 to 3.0.0.
The migration guide is here - github.com/visionmedia/express/wiki/Migrating-from-2.x-to-3.x , but not everything is so simple: the register function, which had problems, was replaced with an engine that works somewhat otherwise.
Here is what a long search and digging in the code gave:
the author of swig himself decided to switch from express.js to consolidate.js. However, you can still make swig work under the third express by adding to swig/index.js:

exports.__express = function (path, options, fn) {
  options = options || {};
  try {
    options.filename = path;
    var tmpl = exports.compileFile(_.last(path.split('/')));
    fn(null, tmpl.render(options));
  } catch (err) {
    fn(err);
  }
};

and in your project itself, replacing the first line with the second :
    app.register('.html', swig);         // для express v.2
    app.engine('.html', swig.__express); // для express v.3

Changes in the express also affected other modules used in my project, in particular socket.io, but this is a completely different story.
I hope the results of my search will help others.

A
Alexey, 2014-03-13
@barsukoff

this entry is enough for me to work phpmyadmin from a folder inside the site:

location /myadmin {
      index index.php;
}

V
Vit, 2014-03-12
@fornit1917

For example something like this:

location /samle {
   root /var/www/test2/sample;
   rewrite ^sample/(.*)$ /$1 break;
}

K
Kev, 2014-03-12
@Kev

With this config "No input file specified."

location /sample {
      index index.html index.php;
      #try_files $uri $uri/ /index.php?$args;
      alias /var/www/test2/sample;
      rewrite ^sample/(.*)$ /$1 break;
      
      location ~ \.php$ {
    include fastcgi_params;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_index index.php;
    fastcgi_param	PATH_TRANSLATED  $document_root$fastcgi_script_name;
    fastcgi_param	SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass   127.0.0.1:9000;
      }
  }

With this 404 Not Found
location /sample {
      root /var/www/test2/sample;
      rewrite ^sample/(.*)$ /$1 break;
  }

In the last example, I change root to /var/www/test2 - again No input file specified.

E
Eugene, 2014-03-12
@Nc_Soft

Set root inside locations, without any set, and in the server section, it is not necessary. Once you ask it, you can't change it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question