简体   繁体   中英

Can we send data to partials in ejs?

**Objective: ** I need to send text into patials in ejs. Say i need to change the title of webpage for different webpage.Since i have refactored the common code and placed into an seperate file. Can i pass data to it

Code

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Home</title>
</head>

Say I need to change the title of the partial for different pages.

If you place the partial for example head.ejs in your code, the data sent to this code will also be sent to head.ejs .

For example if you send the value title to your index.js code, you can put this in your head partial.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM