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 8083315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:25:31+00:00 2026-06-05T17:25:31+00:00

I am working on an offline prototype (html, css and js), and I need

  • 0

I am working on an offline prototype (html, css and js), and I need a simple mechanism in which i can separate my markup into several external template files for better maintenance and to make it reusable..

mainly these external templates will not have any type of data templating, it will contain only static html,

I need to write a script, which will parse all data-template-url attributes, and load the corresponding template file into that DOM element, and if the loaded template has a data-template-url, the script will also do the same (no matter how much nested templates there are in my markup)

<div class="some-component" data-template-url="components/user-details.html">
    <!-- template content will be loaded here -->
</div>

I have done the following script which will do the job, but does not handle nested templates

(function($){

    $(function(){

        var attr = 'data-template-url';

        $('[' + attr + ']').each(function(){
            var $self = $(this)
            ,   url = $self.attr(attr);

            $.get(url, function(data){
                $(data).appendTo($self);
            });
        });

    });
})(jQuery);

appreciate if anyone can help 🙂

  • 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-05T17:25:33+00:00Added an answer on June 5, 2026 at 5:25 pm

    If you want to keep your approach:

    (function($){
    
        $(function(){
    
            var loadTemplates = function () {
    
                var 
                    /* template url attribute */
                    attr = 'data-template-url',
                    /* load status attribute */
                    state = 'data-template-state',
                    /* load done value for status attribute */
                    done = 'ready';
    
                /* for all elements with template url not in ready state */
                $('[' + attr + ']:not([' + state + '="' + done + '"])')
                .each(function () {
    
                    /* fetch url */
                    var url = $(this).attr(attr);
    
                    /* load content and append */
                    $(this).load(url, function () {
    
                        /* set state to ready */
                        $(this).attr(state, done);
    
                        /* do another run for nested templates */
                        loadTemplates();
    
                    });
    
                });
            };
    
            /* start */
            loadTemplates();
        });
    
    })(jQuery);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a web app which will need to work offline. I'm looking
I'm working on iphone application which needs to run offline at an exhibition. It
Working on a rather small, and simple layout, I decided to use Meyer's CSS
I'm working on an offline only help system which requires loading a large amount
I am working offline with SQLite, Javascript and Chrome In my main page (main.html),
I am working on an offline-mode iPhone application in which the first time data
I have an MVC2 web site which I am trying to get working offline
I'm working on an offline html5 app which does a lot of DOM manipulation
I am trying to get a simple (all front-end) application working offline on ipad,
We have an offline set of HTML pages we're working with using HTML5 document

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.