mde / ejs

Embedded JavaScript templates -- http://ejs.co
Apache License 2.0
7.79k stars 843 forks source link

I just can’t solve the problem with include, I tried different methods, different syntaxes #748

Closed mrranger closed 1 year ago

mrranger commented 1 year ago

I also tried express-partials, Please help. ejs: 3.1.9 express: 4.18.2 express-ejs-layouts: 2.5.1 express-partials: 0.3.0 express-session: 1.17.3

TypeError: /home/container/dashboard/views/home/home.ejs:50 48| 49|

50| <%- include ('partials/sidebar') %> 51| 52| 53|

include is not a function

`const express = require('express') const flash = require('connect-flash'); const session = require('express-session'); const partials = require('express-partials'); const passport = require('passport'); const ejsLint = import('ejs-lint'); var EJS = require('ejs');

const fileUpload = require('express-fileupload'); const config = require('../config/config.json')

const app = express();

const path = require('path'); const http = require('http').Server(app); const io = require('socket.io')(http); app.use(partials());

port = config.port;

app.engine('html', EJS.renderFile);

app.set('view engine', 'ejs'); app.set('views', path.join(__dirname, 'views')); app.use(express.static('dashboard/public')); app.use(express.static('dashboard/themes')); app.use(express.urlencoded({ extended: true,limit: '5mb' })); app.use(fileUpload());

require('./auth/passport')(passport);

// Express session app.use( session({ secret: '0tw4cuahvt9m4bt8abaeurhtiac', resave: true, saveUninitialized: true }) );

// Passport middleware app.use(passport.initialize()); app.use(passport.session());

// Connect flash app.use(flash());

// Global variables app.use(function(req, res, next) { res.locals.success = req.flash('success'); res.locals.error = req.flash('error'); next(); });

app.use('/', require('./routes/home.js')); app.use('/', require('./routes/settings.js')); app.use('/', require('./routes/guilds.js')); app.use('/', require('./routes/support.js')); app.use('/', require('./routes/plugins.js')); app.use('/', require('./routes/steamboost.js'));

app.use('/login', require('./routes/login.js'));

http.listen(port)

io.sockets.on('connection', function(sockets){ setInterval(function(){ // Uptime Count let days = Math.floor(client.uptime / 86400000); let hours = Math.floor(client.uptime / 3600000) % 24; let minutes = Math.floor(client.uptime / 60000) % 60; let seconds = Math.floor(client.uptime / 1000) % 60;

var BOTuptime = `${days}d ${hours}h ${minutes}m ${seconds}s` 

// Emit count to browser 
sockets.emit('uptime',{uptime:BOTuptime}); }, 1000);

})

// Error Pages app.use(function(req,res){ res.status(404).render('error_pages/404'); }); `

mde commented 1 year ago

There is something in your application code causing this problem. My suggestion to you is to start with a clean Express app, with only a single EJS page that does nothing but include an EJS file. Then start adding pieces of your app back until you find what is causing the breakage. The EJS include function is incredibly well-tested, and used by millions of people, so it definitely works as described in the docs.

I am closing this issue. If you can create a minimal test that demonstrates an actual problem with EJS, feel free to reopen.