Discover FortressJS - A fast, secure and easy I/O framework
Adrien-fr
65.9K views
Templates
You can manage your templates with pages as you want. For example, you can introduce your own custom variables like __MY_VAR
and manage them in your page controller.
For example, find a way to get this work :
Get the page redirected
1
2
3
4
5
6
7
8
9
10
11
12
13
14
module.exports = homePage;
function homePage(pageConf)
{
child_process.execSync("echo 'TECHIO> open -p 8080 /' > /proc/1/fd/1");
this.code = function(req, res)
{
// change this to use the redirect view
var view = this.view.home;
view = view.replace("__URL__", "/success"); // Change this template variable in redirect view or here
res.end(view);
};
}
1
<html>
Help
Select the right view, and change the template var
Using Pug, a template engine
Pug is a NodeJS template engine. You can discover it here (Pug)[https://pugjs.org/api/getting-started.html].
It's easy to integrate with FortressJS :
npm install pug
Once done, use var pug = require("pug");
to use it.
Try it with this exercise :
- Update
home.page.js
- Go to the fortressjs folder
- Install pug
- Launch FortressJS
Install Jade and use it
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
module.exports = homePage;
function homePage(pageConf)
{
try
{
// require pug here
} catch (e)
{
child_process.execSync("echo 'TECHIO> success false' > /proc/1/fd/1");
return;
}
child_process.execSync("echo 'TECHIO> open -p 8080 /' > /proc/1/fd/1");
this.code = function(req, res)
{
try
{
var view = pug.render(this.view.home.toString());
res.end(view);
}
catch(e)
{
res.end(this.view.error)
}
};
}
Help
install pug with npm in fortressjs folder, and do a "require" of pug in the page
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.