Visionmedia EJS on Client side ( Cordova / PhoneGap )?

727 Views Asked by At

I've been developing a Cordova application.

I know the Visionmedia EJS is a server-side tool. Can I use Visionmedia EJS on client side without node.js?

For instance I want to create 3 part for my application. The parts are layout.ejs, homepage.ejs and user.ejs (a sub-page). Can I arrange like the following? Is it possible?

my layout EJS file

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

my homepage EJS file

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

my user.ejs file

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

There are 1 best solutions below

1
On

Use the following process:

  • Download EJS source files
  • Reference them in the HTML page as the src of <script> tags

Here is an example:

<!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>

References