Visavì
Visavì

Reputation: 2333

Is it possible to use the block tag of Swig in Assemble?

Using assemble-swig, here is my template:

<!doctype html><html lang="it">

<head>
{% include "src/templates/partials/html_header.swig" %}
</head>
<body>
{% include "src/templates/partials/body_header.swig" %}

<header class="articleHeader intro"><div class="inner">
{% block articleheader %}{% endblock %}
</div></header>

<div class="body"><div class="inner">

<article class="main{% if nosidebar %} noSideBarArticle{% endif %}">

{% block content %}{% endblock %}

</article>

{% block sidebar %}{% endblock %}
</div></div>

{% include "src/templates/partials/body_footer.swig" %}
{% block javascript %}{% endblock %}
 </body>
</html>

Here is my page:

---
title: "test"
---

{% block articleheader %}

<h1>Article Header!</h1>

{% endblock %}

{% block content %}

<p>this is the content!</p>

{% endblock %}

The result: No data from the page is show

(content of html_header and body_header goes here...)

<header class="articleHeader intro"><div class="inner">

</div></header>


<div class="body"><div class="inner">

<article class="main">

</article>

(content of html_header and body_footer goes here...)

Only if I use the tag {{body}} in the template all the content of the page is inserted but with no respect for the block tag.

Upvotes: 1

Views: 127

Answers (1)

Visav&#236;
Visav&#236;

Reputation: 2333

Yes, it seems to be possible if you don't use the layout of Assemble.

I get it to work setting the layout property to false in the config:

assemble: {
  options: {
    engine: 'swig',
    ...
    layout: false,
    ...

and then in each file adding:

 {% extends 'src/layouts/default.swig' %}

at the top of the content.

Upvotes: 1

Related Questions