co-views icon indicating copy to clipboard operation
co-views copied to clipboard

relative path error with ninjucks and extending base templates

Open mypark opened this issue 10 years ago • 9 comments

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 %}

mypark avatar Oct 15 '15 20:10 mypark

+1

alexpts avatar Dec 22 '15 14:12 alexpts

PR welcome!

haoxins avatar Dec 22 '15 14:12 haoxins

+1

akuma avatar Mar 19 '16 06:03 akuma

+1

rambo-panda avatar Apr 05 '16 15:04 rambo-panda

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

rambo-panda avatar Apr 06 '16 00:04 rambo-panda

@rambo-panda submit a PR?

haoxins avatar Apr 06 '16 01:04 haoxins

@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']
    }
  }
});

kyuwoo-choi avatar Sep 30 '16 03:09 kyuwoo-choi

+1 with koa-views 4.x

@rambo-panda is right.

solve my promblem

uerbin avatar Oct 14 '16 01:10 uerbin

@rambo-panda @kyuwoo-choi thanks

uerbin avatar Oct 14 '16 01:10 uerbin