Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    nunjucks-appendpublic

    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>

    Keywords

    none

    install

    npm i nunjucks-append

    Downloadsweekly downloads

    12

    version

    0.0.3

    license

    none

    repository

    githubgithub

    last publish

    collaborators

    • avatar