0

All we like simple, structured code that is easy to comply with. We try to bring a difference between appearance and logics. In PHP, for instance, we can use a template mechanism, i.e. create an html-formatted file with php tags that uses some predefined variables that get ready for use through a logic resposible script.

Is there some analog for JavaScript?

What methods do you use to create dynamic content of certain type? (For example list items, complex forms that can be repeated several times)

1
  • 1
    "Thankx" isn't a word, please try to avoid chat speak here. Commented Aug 24, 2011 at 18:44

4 Answers 4

2

There are many js template engin as below. Choose as you want. Handlebars is my suggestion.

  1. Handlebars. http://handlebarsjs.com/
  2. jquery template. http://api.jquery.com/jQuery.template/
  3. Ejs http://embeddedjs.com/.
  4. Underscore has template engin. http://documentcloud.github.com/underscore/#template
  5. trimpath http://code.google.com/p/trimpath/wiki/JavaScriptTemplates
  6. John Resig's micro template engin. http://ejohn.org/blog/javascript-micro-templating/
  7. mustaches is also a good one. https://github.com/janl/mustache.js/
Sign up to request clarification or add additional context in comments.

Comments

1

Underscore.js has simple templating mechanism as well. (And I think it must be in every javascript developer's toolbox).

jQuery's is more sophisticated, though - and probably more useful (Update: but now is deprecated).

Comments

1

I've used things like js-template for client side templates. For server side, whatever template mechanism was present in the system at hand could usually be applied to plain text javascript files.

Comments

0

Try looking into jQuery Templates. It is one of the many solutions available.

1 Comment

@BrandonCraigRhodes wow, that wasn't exactly unexpected, but still. I'm currently using it in a production project and hating it. Well, good to know I guess.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.