Best practice for storing HTML templates on a page?

Web Technologies Web Development 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating
_x000D_ _x000D_ I'm developing a rather heavy JavaScript interface to a site I'm building, and I've decided to use the (recently made official) jQuery templates plugin to generate my elements from my queries to a JSON API. Now, the problem I'm currently having is: I'm prone to have a bunch of these templates around. One for each kind of object, some for lists, some for sections of the page, etc. Is there any preferred way of storing these templates? I've read about defining a

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago
_x000D_ look at https://github.com/inspiraller/STQuery STQuery uses all of the same method names as jquery but instead of manipulating elements on the dom, it works directly on the string: var strTemplate = '

lorem ipsum

lorem ipsum
'; var ST = STQuery(strTemplate); ST.find('h1').html('Hello'); ST.find('.content').html('World!'); var strTemplateUpdated = ST.html(); This keeps logic seperate from the template, ie unobtrusive html templates. The advantages over jquery is that STQuery doesn't have to write to the DOM first, which means you could use web workers or do all your template manipulation on the server. Note: as of this message, stquery has only been written in javascript so would need to be converted to the server side language of choice.

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Important Web Technologies Links