metalsmith / layouts

A metalsmith plugin for layouts
MIT License
116 stars 49 forks source link

Issues with Twig extends/partials #109

Closed jnettik closed 7 years ago

jnettik commented 8 years ago

I'm looking to set up templates with Twig for a project I'm working on. Templates by themselves work fine, however if I try and extend a layout or include a partial I run into issues. My test post's front matter is:


---
title: Test Post
date: 2016-08-13
topic: Lifestyle
layout: blog.twig

---

blog.twig:

{% extends "default.twig" %}

{% block title %}
{{ "#{parent()} Blog" }}
{% endblock %}

{% block content %}
<div class="blog-content">
  {{ parent() }}
</div>
{% endblock %}

and my default.twig template, which I'm extending is:

<!DOCTYPE html>
<html>
  <head>
    {% block metadata %}
    <meta charset="UTF-8">
    {% endblock %}

    <title>{% block title [title, siteName]|join(' - ') %}</title>

    {% block stylesheets %}
    <!-- Styles will go here -->
    {% endblock %}

    {% block scriptsHeader %}
    <!-- Header scripts will go here -->
    {% endblock %}
  </head>

  <body>
    {% block content %}
    {{ contents }}
    {% endblock %}

    {% block scriptsFooter %}
    <!-- Footer scripts will go here -->
    {% endblock %}
  </body>

When I try and compile my test post, I get the error:

Error parsing twig template undefined:
TwigException: Cannot extend an inline template.
{ message: 'Cannot extend an inline template.',
  name: 'TwigException',
  type: 'TwigException' }

What I can't tell is if I have something configured wrong or if there's some feature of Twig missing from the JS version. The existing issues I've read about this seem have been resolved. Thank you for any insight you can provide!

doodzik commented 7 years ago

This unfortunately isn't possible with this library. please use metalsmith-in-place for this