0

我一直在开发一个 Cordova 应用程序。

我知道 Visionmedia EJS 是一个服务器端工具。我可以在没有 node.js 的客户端上使用 Visionmedia EJS 吗?

例如,我想为我的应用程序创建 3 部分。这些部分是 layout.ejs、homepage.ejs 和 user.ejs(一个子页面)。我可以像下面这样安排吗?可能吗?

我的布局 EJS 文件

<!DOCTYPE html>
<html>
  <body>
    <%- body %>
  </body>
</html>

我的主页 EJS 文件

<div>
    <% include user.ejs %>
</div>

我的 user.ejs 文件

<div data-role="page" id="page-user">
    username: <%- user.username %>
    firstname: <%- user.firstname %>
    lastname: <%- user.lastname %>
</div>
4

1 回答 1

1

使用以下过程:

  • 下载 EJS 源文件
  • 在 HTML 页面中将它们作为srcof<script>标签引用

这是一个例子:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <title>EJS - Embedded JavaScript - Demo</title>
    <link rel="stylesheet" href="example.css" type="text/css" media="screen" />
    <script src="../lib/prototype.js" type="text/javascript"></script>
    <script src="../src/ejs.js" type="text/javascript"></script>
    <script src="example.js" type="text/javascript"></script>
</head>

<body id="thebod">
<h1><a href="http://www.edwardbenson.com/projects/ejs/"><img src="ejs.gif" alt="EJS - Embedded JavaScript" /></a></h1>
<h2>Demo Page</h2>
<p>This page is a quickly cobbled together demo of compiling EJS from a DOM source and from a String source. For more information and demos, see <a href="http://www.edwardbenson.com/projects/ejs">EJS on the web</a>.</p>

<div class="example">
<h3>Example 1: Running from the a String</h3>
<h4><a href="#" onClick="testUsingText();return false;">Run</a></h4>
<p>This example compiles and runs EJS from a String stored in the example.js file included with this project.</p>
</div>

<div class="example">
<h3>Example 2: Running from the DOM </h3>
<h4><a href="#" onClick="testUsingDOM();return false;">Run</a></h4>
<p>This example compiles and runs EJS from the DOM node directly below this sentence.</p>
<div id="source_code">
[%  var title = "Items to buy!"; %]
<h1>[%= title %]</h1>
<ul>
[% ['cupcake', 'hardware'].each(function(item) { %]<li>[%= item %]</li>[% }); %]
</ul>
</div>
</div>
<hr>
<div class="output">
<h3>Compiled Code</h3>

<div id="output_code">
</div>
</div>
<div class="output">
<h3>Compilation Results</h3>
<div id="output_results">
</div>
</div>
<br />

</div>
<br /><br /><br />
<p align="center">Copyright &copy; 2007 Edward Benson<br /><a href="http://www.edwardbenson.com/">edwardbenson.com</a></p>
</body>
</html>

参考

于 2015-02-06T01:58:01.833 回答