4/17/2023 0 Comments Pug template engine express![]() get ( '/home', ( req, res ) => home page It's a test view If you wanted to pass data from your Express application to your home view, you can render a variable like so: app. That view will end up creating a HTML template with a h2 tag that wraps the text ‘This is the home page’, and a p tag that wraps the text “It’s a test view”. Now that you’ve done that in your Express app, you can add a template into your views directory as views/home.pug and fill it in: h2 This is the home page Then you can set the view engine to pug when you initialize your app, then make a get call and render your view: const express = require ( 'express' ) const app = express ( ) To install Pug and use it in our Express app, we have to use npm to install it first: $ npm install pug In this breakdown, we’ll introduce the basic syntax and uses of Pug, EJS, and Mustache. ![]() However, the default Jade installed in Express is still using the old version. The default template engine found in Express is Jade, which is now known as Pug. There’s a wide variety of template engines that work with Express. ![]() If you’d like to learn more about Express, follow this link.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |