Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8840645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:30:36+00:00 2026-06-14T10:30:36+00:00

I am new to the world of JavaScript Templating. Here I have a page,

  • 0

I am new to the world of JavaScript Templating.

Here I have a page, in which I don’t know how the template code should be organized.

This is the relevant HTML When the page is first loaded:

...
<table id="color-codes">
  <tr>
    <td>red</td>
    <td>#FF0000</td>
  </tr>
  <tr>
    <td>blue</td>
    <td>#0000FF</td>
  </tr>
  <tr>
    <td>black</td>
    <td>#000000</td>
  </tr>
</table>
...

The user can add colors to the table. Each time a color is added, the browser dispatchs an AJAX request to the server. The server then returns a JSON object that has both the color name and the color code.

Upon receiving the JSON object, the client-end renders the template (below) with the JSON object and then insert the resultant DOM object into the end of the table.

The table-row template:

<tr id='tp-color-entry'>
  <td class='color-name'></td>
  <td class='color-code'></td>
</tr>

Question: Where should I place this template code? In HTML file? Or JS file? If in HTML file, how to prevent it to interfere with the page presentation/layout? If in JS file, do I just save assign it to a variable?

Note that I use Pure for JS Templating and Django as my server-end. And I always try to keep HTML and JS code into separate files.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:30:37+00:00Added an answer on June 14, 2026 at 10:30 am

    You can put it in a script tag with an unrecognized type attribute:

    <script type="text/x-pure-template" id="color-entry-template">
        <tr id='tp-color-entry'>
            <td class='color-name'></td>
            <td class='color-code'></td>
        </tr>
    </script>
    

    Then it’s a simple matter to retrieve the template:

    document.getElementById('color-entry-template').textContent
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im new in this JavaScript world, but i have this problem i want to
I am new to Extjs4 and the javascript world in general. I have looked
I'm very new to the JavaScript library world. I have used JS by itself
I have this simple hello world version of a google map api javascript v3
I have just entered the world of jquery and am pretty new to javascript
am new to this java world.. i just wanted to know how to convert
I'm not new to Javascript but then I realize I don't know how to
I have no idea why this code does not loop as it should. My
I am kind of very new to javascript world. I have a doubt. How
I'm new to JavaScript as well as jQuery. This is the only code I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.