Skip to content

A nunjucks extension that allows one to create a tag and append content to it in subviews

Notifications You must be signed in to change notification settings

faceleg/nunjucks-append

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nunjucks Append

Allows one to define a tag that subviews can append content to. Handy for letting subviews add resources to the head or footer, for example.

Example:

The layout - /views/layouts/default.html:

<!DOCTYPE html>
<html>
    <head>
        <title>The Title</title>
        <link rel="stylesheet" href="/stylesheets/style.css" />

        {% output "javascript" %}
        <script src="/jquery.js"></script>
        {% endoutput %}
    </head>
    <body>
        {% block content %}{% endblock %}
    </body>
</html>

The view - /views/index.html:

{% extends "/layouts/default.html" %}

{% append "javascript" %}
<!-- Will be output beneath jquery.js -->
<script src="/index-script.js"></script>
{% endappend %}

{% block content %}
<div>
    <p>The content</p>
</div>
{% endblock %}

The output:

<html>
<head>
    <title>The Title</title>
    <link href="/stylesheets/style.css" rel="stylesheet">
    <script src="/jquery.js"></script>
    <!-- Will be output beneath jquery.js -->
    <script src="/index-script.js"></script>
</head>

<body>
    <div>
        <p>The content</p>
    </div>
</body>
</html>

About

A nunjucks extension that allows one to create a tag and append content to it in subviews

Resources

Stars

Watchers

Forks

Packages

No packages published