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

TwigException: Cannot extend an inline template. #99

Closed
ghost opened this issue May 5, 2017 · 5 comments
Closed

TwigException: Cannot extend an inline template. #99

ghost opened this issue May 5, 2017 · 5 comments

Comments

@ghost
Copy link

ghost commented May 5, 2017

Not sure if this is the correct place.

I try to use twig.js with koa 2:

const Views = require('koa-views');

app.use(Views('./views', {
	map: {
		twig: 'twig'
	},
	extension: 'twig'
}));

app.use(Route.get('/', async(ctx) => {
	await ctx.render('pages/home');
}));

Now i'll try to use a layout

layout.twig:

<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8" />
	<title>Hello World!</title>
</head>

<body>
	{% block body %}{% endblock %}
</body>

</html>

home.twig

{% extends "../layout.twig" %}

{% block body %}
    Hello World
{% endblock %}

Now i'm getting this error:

Error parsing twig template undefined:
TwigException: Cannot extend an inline template.

  Error: non-error thrown: TwigException: Cannot extend an inline template.
      at Object.onerror (C:\Users\jerom\Documents\programming\test\node_modules\koa\lib\context.js:107:40)
      at onerror (C:\Users\jerom\Documents\programming\test\node_modules\koa\lib\application.js:133:34)

Anyone an idea what i did wrong here?

@int64ago
Copy link
Collaborator

int64ago commented May 6, 2017

Hi, i don't think twig implemented in Node supports layout.

Ref: https://github.com/twigjs/twig.js

Twig.js is currently a work in progress and supports a limited subset of the Twig templating language (with more coming).

I'll close the issue, feel free to ope it if i'm wrong.

@int64ago int64ago closed this as completed May 6, 2017
@vbustamante
Copy link

Hey guys, reading the implementation notes on the twigjs repo, it looks like include and extend are already supported. My problem is a little bit different than Jerome's, since i'm trying to include a twig file inside another, but the error message is exactly the same.

The solution appears to involve passing an allowIncludeTemplates:true option to the engine (ref), but adding it to the opts.options object does not seem to cut it. Now I'm stuck since I don't even know whose problem is this, but maybe is that koa-views isn't passing the option to the twig engine? I dunno

@int64ago
Copy link
Collaborator

int64ago commented Aug 5, 2017

@vbustamante Thanks for the correction, now it seems the problem of consolidate.js, it ONLY passes a data option as parameters, you can't set allowIncludeTemplates by passing the option in koa-views.

@jean-smaug
Copy link

jean-smaug commented Oct 1, 2020

👋 I'm struggling with this issue

Error: non-error thrown: {"message":"Cannot extend an inline template.","name":"TwigException","type":"TwigException"}

The template.html

<!DOCTYPE html>
<html lang="fr">
  <head>...</head>
  <body>
    <main>{% block main %}{% endblock %}</main>
  </body>
</html>

The page that extends

{% extends "template.html" %}

{% block main %}
<p>Hello</p>
{% endblock %}

My config

const views = require('koa-views');

app.use(
  views(pathUtil.viewsPath(), {
    extension: 'html',
    map: {
      html: 'twig',
    },
    options: {
      allowIncludeTemplates: true,
    },
  }),
);

What I am doing wrong ?

@jean-smaug
Copy link

jean-smaug commented Oct 1, 2020

Update
I checked the code of consolidate and the option isn't allowIncludeTemplates but it's allowInlineIncludes.

But it still doesn't work :'(

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

3 participants