2

By using java i want to convert javascript template (i try to make ) to pure javascript

Here is example : Input

<? function test() 
{
    return "Just a message";
}
if("a"=="b")
{
?>
<h1><?=test()?></h1>
<?
}
?>
<?=test()?>

</head></html>

output pure js example

out.print("<html><head>");
function test() 
{
    return "Just a message";
}
out.print("<h1>");
if("a"=="b")
{
out.print(test());
}

out.print("</h1>");
out.print("</head></html>");

I need a function to convert javascript template to pure javascript an eval it later . p/s a example using javascript function here http://ejohn.org/blog/javascript-micro-templating/ but i'm not sure it work perfectly when given conplex template

0

1 Answer 1

1

You can match every pair. And each pair is javascript and the rest is outputted using out.print(...). A simple regex can do the job.

Or you can look at template engines which are fully tested and supported, such as: http://mustache.github.io/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.