How to use multiple partials with Swig?

Green

Swig doesn't render some partials in my view. How to pass blocks the right way? What file should extend what?

I have such a structure of my view:

// files
header.html   // <- partial
header_logo.html   // <- partial
layout.html   // <- layout
index.html   // <- page

index.html is the one that Swig renders. It looks like this:

{% extends 'layout.html' %}
{% extends 'header.html' %}
{% extends 'header_logo.html' %}

{% block head %}
    {% parent %}
    <link href="/assets/css/index/index.css" rel="stylesheet">
{% endblock %}

{% block content %}

     {% block header_logo %}{% endblock %} // <- This one doesn't render

     .... html content code goes here ....
{% endblock %}

layout.html looks like this:

<!DOCTYPE html>
<html lang="en">
  <head>
    {% block head %}
        <link href="/assets/css/index/layout.css" rel="stylesheet">
    {% endblock %}
  </head>
  <body>

    {% block header %}{% endblock %}

    {% block content %}{% endblock %}  

  </body>
</html>

header.html looks like this:

{% extends 'layout.html' %}

{% block header %}
    ... html code goes here ...
{% endblock %}

header_logo.html looks like this. And this one doesn't render.

{% extends 'layout.html' %}

{% block header_logo %}
    ... html code goes here ...
{% endblock %}
Paul Armstrong

You can only extend one template per file. What you want to do is something like this...

  • index.html extends header_logo.html
  • header_logo.html extends header.html
  • header.html extends layout.html

Or, it looks like you want to include header_logo in your index.html template, not extend from it. You might be better off doing something like this...

index.html

{% extends 'layout.html' %}

{% block header %}{% include 'header.html' %}{% end block %}
{% block content %}
    {% include 'header_logo.html' %}
...
{% endblock %}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Use AJAX to display multiple partials

From Dev

Codeigniter+Angular Js: How to use partials?

From Dev

How to use partials in Comfortable Mexican Sofa?

From Dev

How to create layout that use header and footer partials

From Dev

Rails 4: How to use form_for and partials

From Dev

How to use partials or helpers in mybatis XML mapper?

From Dev

how to use enum in swig with python?

From Dev

How to use LPCWSTR with Go and Swig?

From Dev

How to Use SWIG for STL Maps?

From Dev

Change form multiple partials

From Dev

how to properly use {% include %} tag to render a template (like partials) in django?

From Dev

How to use Nunjucks' partials / macros / includes with metalsmith-in-place?

From Dev

how to use C++ macro in SWIG interface

From Dev

How to use SWIG to wrap std::function objects?

From Dev

How to use swig template in geddy js

From Dev

how to cache angularjs partials?

From Dev

how to cache angularjs partials?

From Dev

How to update partials

From Dev

Is there an example how to use SWIG to generate C++ buidings with go build?

From Dev

How to use 3-dimensional numpy arrays with swig

From Dev

how to use break in for loop of swig template node js?

From Dev

How to use swig with compiled dll and header file only

From Dev

how to use break in for loop of swig template node js?

From Dev

Using one json file in multiple partials

From Dev

Unable to use partials in handlebars Email templates

From Dev

Angular JS: How to load js files in partials

From Dev

How to specify Middleman's partials directory globally?

From Dev

How does Partials / Template inheritance work in Mustache?

From Dev

How to stop count from duplicating partials in #show?

Related Related

HotTag

Archive