簡體   English   中英

如何修復傳遞給部分數據的部分作為屬性添加的錯誤

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

我對網頁設計很陌生,我正在嘗試為我的投資組合網站設置我的部分。 我希望能夠通過 ejs 文件將數據傳遞給部分以設置標題和描述。

使用我在傳遞數據時已經找到的一些信息,我創建了兩個變量,title 和 description,然后將它們傳遞給 partials/header.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} %>

頭文件.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 %>>           
        <% } %>
...

我希望標題應該設置為變量標題(“主頁的標題”),並且描述內容屬性應該設置為變量描述(“主頁的描述”)。

標題工作正常,但描述輸出:

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

以 description、for、the、home、page 作為屬性。

有什么我沒有看到的,或者我是否錯誤地使用了 <%= %> ?

額外問題:我所做的是否合理/預期/標准,或者在典型站點中是否有更好的方法來完成此任務?

正確的方法是將描述放在雙引號中

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM