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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:38:08+00:00 2026-06-06T14:38:08+00:00

I am loading some template files into my application using require.js like so: define(function(require)

  • 0

I am loading some template files into my application using require.js like so:

define(function(require) {
    var App = require('app'),
    TeamListTmpl = require('text!templates/team-list.html'),
    PlayerListTmpl = require('text!templates/player-list.html'),
    PlayerItemTmpl = require('text!templates/player-item.html');

Then, using Backbone, I am referencing the template like so:

var PlayerItemView = Backbone.View.extend({
    tagName: "li",
    template: _.template(PlayerItemTmpl),

It’s kind of annoying having individual template files and I’d like to combine all the templates into one html file and pull out individual elements. I tried this:

   define(function(require) {
        var App = require('app'),
        Templates = require('text!templates/templates-combined.html');

Where the templates-combined html file looks like this:

<div id="some-element-1">1</div>
<div id="some-element-2">2</div>
<div id="some-element-3">3</div>

But this doesn’t work for some reason:

$(Templates).find("#some-element-1").html();

I also tried:

$('#some-element-1', Templates).html();

Is there any way to extract the individual template files from the one combined file without adding it to the DOM first? Perhaps using javascript templates instead? Any help would be greatly appreciated.

  • 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-06T14:38:09+00:00Added an answer on June 6, 2026 at 2:38 pm

    I’m guessing that you want to use filter rather than find:

    var some_element_1 = $(Templates).filter('#some-element-1').html();
    

    You see, find searches within the $(Templates):

    Get the descendants of each element in the current set of matched elements, filtered by a selector, jQuery object, or element.

    so it would find things inside those three <div>s but not the <div>s themselves; filter, on the other hand, searches through the set of elements:

    Reduce the set of matched elements to those that match the selector or pass the function’s test.

    When you say var x = $(Templates), your x looks like this:

    [
       <div id="..."></div>,
       <div id="..."></div>,
       <div id="..."></div>
    ]
    

    If we look at the descendants of those <div>s (i.e. find), we won’t find #some-element-1 but if we look at the set of matched elements themselves (i.e. filter) then we will find #some-element-1.

    If for some reason you really want to use find, you could wrap another <div> around your templates to force them to be descendants of $(Template):

    <div>
        <div id="some-element-1">1</div>
        <div id="some-element-2">2</div>
        <div id="some-element-3">3</div>
    </div>
    

    I’d also recommend that you wrap your templates in <script> elements rather than <div>s:

    <script type="text/x-template" id="some-element-1">1</script>
    <script type="text/x-template" id="some-element-2">2</script>
    <script type="text/x-template" id="some-element-3">3</script>
    

    The browser will treat <script>s as opaque black boxes (provided you use the right type attribute) but it might try to interpret and correct the contents of <div>s. The problem is that your templates might not be valid HTML until after you’ve processed them and filled them in; if you let a browser get its hands on invalid HTML it might try to correct it and that can make a big mess of your templates.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am loading some text dynamically into a div, but have the problem that
I am using joomla for loading some static content for my web application. now
Summary of the issue: When I am loading some data into my iPhone application
I have a setup like this... $(document).ready(function(){ var model = { /* some variable
I'm loading in some HTML content like this: $('#scores').load('scores.php #scores'); Note that It is
I'm loading HTML-formatted content into my app from a web service, then plugging that
I would like to load some content using AJAX and Shadowbox Basically I would
I am loading some html via $.get() into a Jquery-dialog-popup. Upon clicking a link
I am loading some content via Ajax. After the load completes I want to
I'm loading some HTML via Ajax with this format: <div id=div1> ... some content

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.