Plain Text in Pug View Engine
Last Updated :
13 Mar, 2024
Plain text in Pug can be retrieved via a variety of methods, each with its own syntax and advantages. This article will go over many strategies for achieving plain text output in Pug, outlining each approach step by step. We'll also include examples, installation instructions for required modules, package.json dependency updates, and resources for further learning.
We will discuss the following approaches to implement Plain Text in Pug View Engine:
Using `|` followed by text content:
This method requires typing the | character followed by the required plain text. For example:
p
| This is plain text in Pug.
Using interpolation with `#{}` Syntax:
Interpolation allows you to integrate dynamic content or variables within your text. For plain text, it can be used as follows:
p
|#{'This is another way to include plain text in Pug.'}
Using `.` Followed by Text Content:
The `.` followed by text content is another way to add plain text:
p.
This is yet another method to add plain text.
Steps to Implement Plain Text in Pug View Engine:
Step 1: Create a NodeJS application using the following command:
npm init -y
Step 2: Install required Dependencies using the following command.
npm i pug express
Project Structure:

The updated dependencies in package.json file will look like:
"dependencies": {
"express": "^4.18.2",
"pug": "^3.0.2"
}
Example: This example implements plain text in Pug View Engine
HTML
doctype html
html
head
title Example Pug Template
body
// Unescaped Text
p
| This is plain text.
| It won't be escaped.
// Block Expansion
p.
This is a long paragraph of plain text.
It spans multiple lines without indentation.
// Interpolation
- let name = "GFG"
p Hello #{name}, welcome to our website.
// Script Tags
script.
var data = {
"key": "value",
"number": 42
};
// Tag Attribute Value
a(href="#") Click here for more information
Output:
Plain Text in Pug View Engine
Similar Reads
Pug View Engine Installation Pug, once known as Jade, makes writing HTML codes eÂasy for NodeJS and web browsers. It's cleÂar syntax and handy features speeÂd up web work and keep things simpleÂ. This quick guide will go over what you neeÂd to use Pug, how to install it, and what it does, and will give you cleÂar steps along wi
2 min read
Tags in Pug View Engine Tags play a crucial role in Pug templates, allowing developers to create structured and dynamic HTML content. Let's explore the concept of tags in Pug in detail. Table of Content What are Tags in Pug?Tag AttributesClass and ID AttributesSelf-Closing TagsBlock ExpansionDynamic Tag NamesSteps to Setup
4 min read
Headings in Pug View Engine Pug.js is a template engine for Node.js and browsers to render dynamic reusable content. At compile time, the template engine compiles our Pug template code to HTML. Pug has many powerful features like conditions, loops, includes, and mixins using which we can render HTML code based on user input or
2 min read
Pug View Engine - Iteration Pug is a template engine for NodeJS and browsers to render dynamic reusable content. At compile time, the template engine compiles our Pug template code to HTML. Pug has many powerful features like conditions, loops, includes, and mixins using which we can render HTML code based on user input or ref
4 min read
Filters in Pug View Engine Pug is a template engine that can be used to create HTML documents. It's used to write templates that are then compiled into functions that take in data and render HTML documents. We will discuss the different types of Filters in Pug Template and their Approaches: Table of Content 1. :markdown:2. :j
4 min read