Created
December 23, 2013 18:40
-
-
Save yamatt/8102332 to your computer and use it in GitHub Desktop.
Simplification of an issue I had with Swig where you could not replace blocks conditionally when doing template inheritance.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var app = require("express")(); | |
| var swig = require('swig'); | |
| app.engine('swig.html', swig.renderFile); | |
| app.set('view engine', 'swig.html'); | |
| app.set('views', __dirname); | |
| app.get("/loggedin", function (req, res) { | |
| res.render("default", {loggedin: true}); | |
| }); | |
| app.get("/loggedout", function (req, res) { | |
| res.render("default", {loggedin: false}); | |
| }); | |
| app.listen(3000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Swig Conditional Template Inheritance</title> | |
| </head> | |
| <body> | |
| {% block content %} | |
| <p>Welcome loggedout user</p> | |
| {% endblock %} | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {% extends "base.swig.html" %} | |
| {% if loggedin %} | |
| {% block content %} | |
| <p>You are logged in.</p> | |
| {% endblock %} | |
| {% endif %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment