ejs

node ejs reference error data not defined at eval when handing data to view

前提是你 提交于 2021-02-19 07:54:06
问题 i've been closing in on a node application using express and ejs, but when i try to hand data to my view from the controller like so var myData = { theData: data }; res.render(path.join(__dirname + '/../views/index'), myData); i get a nice error ReferenceError:.. myData is not defined eval (from ejs lib) when trying to access myData in the view like so var data = <%-myData%>; or in any other way basically, i've tried stringifying the data, wrapping it in another object and stuff like that but

单页应用SPA做SEO的一种清奇的方案

一笑奈何 提交于 2021-02-16 12:03:58
单页应用SPA做SEO的一种清奇的方案 网上有好几种单页应用转seo的方案,有服务端渲染ssr、有预渲染prerender、google抓AJAX、静态化。。。这些方案都各有优劣,开发者可以根据不同的业务场景和环境决定用哪一种方案。本文将介绍另一种思路比较清奇的SEO方案,这个方案也是有优有劣,就看读者觉得适不适合了。 项目分析 我的项目是用react+ts+dva技术栈搭建的单页应用,目前在线上已经有几十个页面,若干个sdk和插件在里面。 考虑想用服务端渲染来做seo,但是我的项目已经开发了这么多,打包配置、代码分割、语法兼容、摒弃浏览器对象,服务端思想,这么多的点需要考虑,还不如换个框架重新开发呢,所以改造成本太大😱,服务端渲染不适合我这种情况。 预渲染虽然是开发成本最低的,但毕竟是生成一张一张的静态html,而我的seo需求是能够让蜘蛛抓取到我的社区论坛下的每一篇帖子,这样子下来一篇帖子就是一份html,再加上分页,那得多大的量级来存储啊😰,而且网站更新就更麻烦了,这个方案也不太适合。 google.....Emmmm.........................下一个 静态化也是跟预渲染差不多。。。 隆重介绍 以前写过一种单页应用seo的方案,就是自己先在本地用爬虫做预渲染,生成同样目录结构的静态化的html

Syntax highlight for .ejs files in vim

三世轮回 提交于 2021-02-15 09:06:43
问题 What is the best way to make vim highlight ejs (http://embeddedjs.com/) files? Is it possible to set up html highlight for the file in general and javascript highlight to it's parts inside <% %>? Appreciate your help! 回答1: Credits goes to @inkedmn just wanted to point out that html binding works way better, therefore put this in your ~/.vimrc file: au BufNewFile,BufRead *.ejs set filetype=html 回答2: Here's something I whipped up today (made some modifications to the eruby script). It requires

Page Redirecting issues Node-js

≯℡__Kan透↙ 提交于 2021-02-11 14:48:28
问题 I'm trying to open places.ejs file on clicking the submit button on show.js page, just like the show.ejs page opens on clicking the submit button on new.ejs file, but a reference error is occurring. Please help me fix the error. I'm attaching herewith my routes.js code and a part of my index.js code Any help would be highly appreciable. Thank you routes.js const { con, sessionStore } = require('./config/db'); exports.new = function(req, res){ message = ''; if(req.method == "POST"){ const post

Calling external api endpoints when working with node and ejs and geting the details for your users

丶灬走出姿态 提交于 2021-02-11 07:28:09
问题 i have a signup and login form,am using ejs to render as view, i have been given some api endpoint to call, and i have added them to their ejs form action views when i fill in the user details in my ejs view form i get this response. i get this when am trying to register a user { "status": 200, "message": "Account created successfully.", "data": { "name": "name of user", "email": "user email", "password": "$2b$10$0IPgBNCJhjjkasdkGb2y0CviOuxRe/bAfhFqFDqrofMaCz5f0SMtwkgBxIzm" } } i get this

Calling external api endpoints when working with node and ejs and geting the details for your users

房东的猫 提交于 2021-02-11 07:27:30
问题 i have a signup and login form,am using ejs to render as view, i have been given some api endpoint to call, and i have added them to their ejs form action views when i fill in the user details in my ejs view form i get this response. i get this when am trying to register a user { "status": 200, "message": "Account created successfully.", "data": { "name": "name of user", "email": "user email", "password": "$2b$10$0IPgBNCJhjjkasdkGb2y0CviOuxRe/bAfhFqFDqrofMaCz5f0SMtwkgBxIzm" } } i get this

How to write markdown language in HTML language?

泄露秘密 提交于 2021-02-10 19:19:36
问题 # (and ## and ### ) in md files has the meaning of header 1 (2, 3). This md (markdown) header is used by a table of content widget I developed. I want to use a md header (written as # ) that is defined in ejs (template engine) html layout file. How to write # in ejs (html) language so that it is also used by TOC widget same way as # in markdown md file? To be more clear: The # in markdown md file language is the same as <%= header %> when written in ejs (html) language? I am looking how to

React unique key when mapping warning

。_饼干妹妹 提交于 2021-02-10 05:17:35
问题 I'm quite new to react and I'm facing a problem I can't solve. Here is my react component: import React from 'react'; import Header from './Header'; import ContestPreview from './ContestPreview'; class App extends React.Component { state = { pageHeader: 'Naming Contests', whatever: 'test' }; render() { return ( <div className="App"> <Header message={this.state.pageHeader} /> <div> {this.props.contests.map(contest => <ContestPreview key={contest.id} {...contest} /> )} </div> </div> ); } }

How to set character limits in content in ejs template

不羁岁月 提交于 2021-02-08 08:13:02
问题 I am fetching content from Mognodb in EJS template. I have description field which contains more then 500 characters, but I want to show only 50 Characters in my view. Can anyone tell me how to do it. 回答1: In the view you can use JavaScript String.prototype.substring(): <%= description.substring(0, 50) %> Within MongoDB you can use $substr to return a new field with the desired 50 characters: db.collectionName.aggregate([{ $project: { title: 1, shortDescription: { $substr: ["$description", 0,

How to set character limits in content in ejs template

╄→гoц情女王★ 提交于 2021-02-08 08:12:39
问题 I am fetching content from Mognodb in EJS template. I have description field which contains more then 500 characters, but I want to show only 50 Characters in my view. Can anyone tell me how to do it. 回答1: In the view you can use JavaScript String.prototype.substring(): <%= description.substring(0, 50) %> Within MongoDB you can use $substr to return a new field with the desired 50 characters: db.collectionName.aggregate([{ $project: { title: 1, shortDescription: { $substr: ["$description", 0,