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

  • SEARCH
  • Home
  • 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 8177123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T23:25:55+00:00 2026-06-06T23:25:55+00:00

I am reading about templating with Mustache.js. What i don’t understand is how is

  • 0

I am reading about templating with Mustache.js. What i don’t understand is how is where to put the templates. I don’t wont them in the same file.

$.get('test.htm', function(templates) {
    // Fetch the <script /> block from the loaded external
    // template file which contains our greetings template.
    var template = $(templates).filter('#tpl-greeting').html();
    $('body').append(Mustache.render(template, templateData));
});


//test.htm 
<script id="tpl-greeting" type="text/html">
<dl>
    <dt>Name</dt>
    <dd>{{name}}</dd>
    <dt>Time</dt>
    <dd>{{timeNow}}</dd>
</dl>
</script>

Do I have to create a controller that returns my template or can i reference it?

  • 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-06T23:25:57+00:00Added an answer on June 6, 2026 at 11:25 pm

    There are several approaches to doing this.

    1. If you are using a server side scripting language like PHP, just include them in a seperate .mst (the extension could be anything you want actually) file within the JS. For example,
      var _templateName = <?= JS::mustache('content/templateName.mst') ?>;. Thus, when the JS is actually rendered, it will be rendered with the markup but the code will still be maintainable. Besides, with this approach, if you’re using an CDNs, your site will benefit greatly with the cached JS.
    2. The other approach is to load external HTML files with any of jQuery’s $.get, $.getJSON, etc. methods. A more detailed implementation of this is given here.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After reading about CORS (Cross-Origin Resource Sharing), I don't understand how it improves security.
Reading about Kohana templates and saw something I've never seen before: $this->template->title = __('Welcome
I am reading about what an interface contains and I understand in addition to
After reading about CCR : http://www.infoq.com/news/2008/12/CCR I get the impression that it does pretty
After reading about the differences between appSettings and applicationSettings in a web.config file, I'd
I have been reading about websockets and also about socket.io. I understand websockets are
Reading about both separatedly, looks like the same, html+xml+javascript. What's the difference between then?
While reading about shell scripts and temporary file handling, I came across Symlink Exploits.
After reading about it for so long, I now have chance to get my
Instead of me spending the next day (or year) reading about them all, are

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.