客户端的Visionmedia EJS(Cordova / PhoneGap)?

时间:2014-11-29 15:01:04

标签: cordova client-side porting ejs embedded-javascript

我一直在开发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>

1 个答案:

答案 0 :(得分:1)

使用以下过程:

  • 下载EJS源文件
  • 在HTML页面中引用它们作为src代码的<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>

<强>参考