tj / co-views

Higher-level template rendering for node.js using generators
173 stars 24 forks source link

relative path error with ninjucks and extending base templates #24

Open mypark opened 8 years ago

mypark commented 8 years ago

If you extend a base layout using nunjucks with co-views, it seems to lose the relative path and requires you to set the full path

For instance, this template will only work if you use the full absolute path to layout.html, otherwise it will error Error: template not found: layout.html

render.js

var views = require('co-views');
module.exports = views(__dirname + '/../views', {
    map: { html: 'nunjucks', default:'html' }
});

index.html

{% extends "layout.html" %}
{% block body %}
<h1>{{ title }}</h1>
This is a test page with a layout
{% endblock %}
alexpts commented 8 years ago

+1

haoxins commented 8 years ago

PR welcome!

akuma commented 8 years ago

+1

rambo-panda commented 8 years ago

+1

rambo-panda commented 8 years ago

https://github.com/tj/consolidate.js/blob/master/lib/consolidate.js#L1044 https://mozilla.github.io/nunjucks/api.html#renderstring

Same as render, but renders a raw string instead of loading a template.

Should not use renderString

haoxins commented 8 years ago

@rambo-panda submit a PR?

kyuwoo-choi commented 7 years ago

@rambo-panda is right. I think both consolidate.js & co-views should be fixed. passing co-views "dir" param to consolidate?

In the mean time I can make it work like this. It looks dumb but it is the only solution we have.

const render = views(__dirname + '/../views', {
  default: 'njk',
  map: {
    njk: 'nunjucks'
  },
  locals: {
    settings: {
      views: [__dirname + '/../views']
    }
  }
});
uerbin commented 7 years ago

+1 with koa-views 4.x

@rambo-panda is right.

solve my promblem

uerbin commented 7 years ago

@rambo-panda @kyuwoo-choi thanks