简体   繁体   English

如何修复传递给部分数据的部分作为属性添加的错误

[英]How to fix error with parts of the data passed through to partial being added as attributes

I'm pretty new to web design and I'm trying to set up my partial for my portfolio website.我对网页设计很陌生,我正在尝试为我的投资组合网站设置我的部分。 I want to be able to pass data through the ejs file to the partial in order to set the title and the description.我希望能够通过 ejs 文件将数据传递给部分以设置标题和描述。

Using some information I already found on passing data, I created two variables, title and description and then pass them to the partials/header.ejs.使用我在传递数据时已经找到的一些信息,我创建了两个变量,title 和 description,然后将它们传递给 partials/header.ejs。

At the top of home.ejs:在 home.ejs 的顶部:

<% var title = "The title for the Home Page" %>
<% var description = "The description for the home page" %>
<%- include partials/header.ejs {title: title, description: description} %>

Header.ejs头文件.ejs

...
<head>
        <!-- Page Title -->
        <% if (title !== null) { %>
            <title><%= title %></title> 
        <% } else { %>
            <title>Default Title</title>
        <% } %>
        <!-- Page Description -->
        <% if (description !== null) { %>
            <meta name="description" content= <%= description %>>           
        <% } %>
...

I expect that the title should be set to the variable title ("The title for the Home Page") and that the description content attribute should be set to the variable description ("The description for the home page").我希望标题应该设置为变量标题(“主页的标题”),并且描述内容属性应该设置为变量描述(“主页的描述”)。

The title works correctly, but the description outputs:标题工作正常,但描述输出:

<meta name="description" content="The" description for the home page>

with description, for, the, home, page all as attributes.以 description、for、the、home、page 作为属性。

Is there something I'm just not seeing or am I using the <%= %> incorrectly?有什么我没有看到的,或者我是否错误地使用了 <%= %> ?

Bonus question: Is what I'm doing reasonable/expected/standard, or is there a better way of accomplishing this task in typical sites?额外问题:我所做的是否合理/预期/标准,或者在典型站点中是否有更好的方法来完成此任务?

正确的方法是将描述放在双引号中

<meta name="description" content=" <%= description %>">      

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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