2012-12-06 74 views
0

我正在嘗試利用Node/Express的JShare模塊。麻煩轉換這個玉到EJS

在Github上給出的例子說:

Next, you need to make a call out to the JShare helper method in your layout file:

!!! 
html 
    head 
    title= title 
    link(rel='stylesheet', href='/stylesheets/style.css') 
    !{includeJShare()} 
    body!= body 

所以,這個例子是翡翠。我正在使用EJS,並且對於我來說,我無法弄清楚如何實施助手方法......這似乎很簡單,但我不確定在Jade中做什麼,或者如何在EJS中複製它。

+0

'includeJShare()'做了什麼?因爲在ejs中你可以做'<%include filename%>' – chovy

回答

1

!{var}是在翡翠中的非插值插值。你應該可以在ejs中做同樣的事情:

<%- includeJShare() %> 

這應該寫在<script>標籤。

編輯

如果EJS試圖解析include,提交補丁請求https://github.com/brooklynDev/JShare/issues(或EJS),並在此期間進入node_modules/JShare/jshare.js和更改res.locals.includeJShare只是res.locals.JShare,然後在你的ejs中使用JShare()

+0

這是我的猜測,但是它返回了: 錯誤:ENOENT,沒有這樣的文件或目錄'C:\ ... \ htdocs \ www \ _oodle \ views \ JShare()。ejs'' 我認爲它試圖用「include」關鍵字解析它......就像@chovy指出的那樣,它是一個關鍵字,但我試圖運行的是實際的函數「includeJShare」。 – minttoothpick

+0

啊是的。這個錯誤本來是很好的發佈!現在,進入node_modules/JShare/jshare.js並將includeJShare更改爲JShare,然後在您的ejs中使用JShare()。然後在此處提交問題:https://github.com/brooklynDev/JShare/issues – glortho

+0

謝謝!作品膨脹。它必須以'<% - JShare()%>'的形式進入,以便它不會繞過'script'的html標籤。 – minttoothpick