我對網(wǎng)頁設(shè)計很陌生,我正在嘗試為我的投資組合網(wǎng)站設(shè)置我的部分。我希望能夠通過 ejs 文件將數(shù)據(jù)傳遞給部分以設(shè)置標題和描述。使用我在傳遞數(shù)據(jù)時已經(jīng)找到的一些信息,我創(chuàng)建了兩個變量,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 %>> <% } %>...我希望標題應(yīng)該設(shè)置為變量標題(“主頁的標題”),并且描述內(nèi)容屬性應(yīng)該設(shè)置為變量描述(“主頁的描述”)。標題工作正常,但描述輸出:<meta name="description" content="The" description for the home page>以 description、for、the、home、page 作為屬性。有什么我沒有看到的,或者我是否錯誤地使用了 <%= %> ?額外問題:我正在做的事情是否合理/預(yù)期/標準,或者在典型站點中是否有更好的方法來完成此任務(wù)?
如何修復(fù)傳遞給部分數(shù)據(jù)的部分作為屬性添加的錯誤
動漫人物
2021-07-13 12:14:29