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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:27:57+00:00 2026-06-03T16:27:57+00:00

More than a specific answer I’m trying to get recommendations on best practices when

  • 0

More than a specific answer I’m trying to get recommendations on best practices when deciding how to structure view code. In my current project I have a clear/clean mapping of models to views but all these are presented inside a pretty standard container with global navigation elements. For the sake of this question, picture it this way:

  • Header
    • tabs
  • cards
    • card 1
    • card 2
    • card 3

You click on a header tab and a card slides in. the cards themselves have a back button that slides it out to reveal the previously displayed card. The actual content of the card is generated by another view which likely maps to a model. I guess it’s not that much different than common interface patterns in iOS or Android.

Anyways, I want to have a view class called “Card” with a template with the navigation for the card, and whatever else goes in every card. Then I’d like to somehow pass the content of the card to it.

Can I create a Card class and then extend it to create the subclasses (ie: subviews)? So, say I have a model called UserModel and a view called UserView that takes care of the form for that model, I want to do something like:

var Card = Backbone.View.extend();
var UserView = Card.extend();

Then when rendering have that result in, say:

<!-- code from Card -->
<div class="card">
    <nav></nav>

    <!-- code from UserView -->
    <div class="user">
        ...
    </div>
    <!-- END code from UserView -->


</div>
<!-- code from Card -->

I realize a quick way to do this would be to simply manually grab the Card template from every view that I need wrapped, etc… but that feels wrong.

Does that make sense?

Oh… keep in mind that part of the advantage that I’m hoping this has is that I can interact with the UserView instance and have those trigger the necessary methods in the parent class. So…

var uv = new UserView();
uv.render() // <- should render the user view with the card wrapped around it.

I don’t want to have to manually render the card, of course.

How would you structure it?

Thanks!

  • 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-03T16:27:59+00:00Added an answer on June 3, 2026 at 4:27 pm

    Since you asked specifically for best practices and it seems like you’re starting into backbone let’s first start with some basics.

    Backbone has views that are defined with a template engine. The default template engine is underscore.js but a far better template engine is mustache.js or better yet it’s higher level wrapper handlebar.js (HandleBarJS Website). This let’s you structure your view and subview exactly like you described below all into one template with markers for being filled in with logic and thus bringing you down to only one big render event.

    Now that you’ve got a good template to inject your model into you still want to make that render event perform well so let’s make sure you precompile your template. For a good reason to understand why this is necessary read this article (Performance benefit of Precompiling templates). Handlebar.js has a method to precompile your templates so I won’t give samples here.

    Now the last step is build up your model. If you build it in JSON format you can simply just ‘execute’ your template with the model.

    var context = {title: "My New Post", body: "This is my first post!"}
    var html    = template(context);
    

    I have used Handlebar for illustrative purposes as the template creation is much easier IMHO but really anything will work with this model.

    Hope that get’s you on the right path.

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

Sidebar

Related Questions

This is more of an open question rather than looking for one specific answer.
I have more than one Event Listener that calls a specific function, and I
This is more a 'wonder why' than a specific issue but look at the
This is more of an algorithmic dilemma than a language-specific problem, but since I'm
How do I create more than 40-50 textfields and labels in a single view
Edit: Jeremy Wall helped me realize I had asked a question more specific than
I'm trying to figure out how to get the current space # from mission
this is more of an algorithmic question rather than a specific language question, so
Adding more than one child to a WPF StatusBar results in poor layout with
Page_Load Calls more than once (4 times in my case) in FireFox but in

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.