Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
demo for nunjucks
- Loading branch information
Daley
committed
Feb 20, 2024
1 parent
aee3d34
commit b2e784f
Showing
10 changed files
with
834 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
|
||
.emoji p { | ||
|
||
} | ||
|
||
.bodyclass p { | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,8 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Emoji Lister</title> | ||
</head> | ||
<body> | ||
<h1>Emoji Lister for {{ name | upper }}</h1> | ||
<main> | ||
{% for code, url in emojis %} | ||
<img src="{{ url }}" alt="{{ code }}" title="{{ code }}"> | ||
{% endfor %} | ||
</main> | ||
</body> | ||
</html> | ||
{% extends "parent.njk" %} | ||
|
||
{% block main %} | ||
{% for code, url in emojis %} | ||
<img src="{{ url }}" alt="{{ code }}" title="{{ code }}"> | ||
{% endfor %} | ||
{% endblock %} | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>{{ title }}</title> | ||
<link rel="stylesheet" href="/css/style.css"> | ||
</head> | ||
<body class="{{bodyClass}}"> | ||
<h1>{{ title }}</h1> | ||
<main> | ||
{% block main %}No template content specified{% endblock %} | ||
</main> | ||
</body> | ||
</html> |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const express = require('express') | ||
const nunjucks = require('nunjucks') | ||
// Import JSON dataset | ||
const data = require("./data.json") | ||
const app = express() | ||
const port = 3000 | ||
|
||
// Tell nunjucks where your template files are located (e.g., 'views' directory) | ||
nunjucks.configure('views', { | ||
autoescape: true, | ||
noCache: true, // <-- Should only be true when developing | ||
express: app | ||
}); | ||
|
||
// Endpoint for /characters shows all characters | ||
app.get('/characters', function (req, res) { | ||
res.render('default.njk', { | ||
title: "Rick and Morty", | ||
data: data | ||
}); | ||
}); | ||
|
||
// Endpoint for /characters/:id shows details for ONE characer | ||
app.get('/character/:id', function (req, res) { | ||
res.render('character.njk', { /* character data goes here */ }); | ||
}); | ||
|
||
app.listen(port, () => { | ||
console.log(`Example app listening on port ${port}`) | ||
}) |
Oops, something went wrong.