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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:43:45+00:00 2026-06-14T21:43:45+00:00

I am trying to generate a modal for each of my posts so that

  • 0

I am trying to generate a modal for each of my posts so that each post has a modal containing the post content(and eventually comments). When the comment link is clicked the modal will appear. The thing is I have to create a bootstrap modal block for each post so i decided it would be easiest to do this in my backbone template. Why isn’t this working?

Here is my code:

app/assets/templates/posts/index.jst.eco

<% for post in @posts.models: %>
<tbody><td>
<%= post.get('content') %>
</td></tbody>
<tr><td>
<a href="#<%= post.get('id') %>">Comment</a>
</td></tr>
<div class="modal" id="post-<%= post.get('id')%>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<%= post.get('content') %>
</div>
</div>
<% end %>

app/assets/javascripts/routers/posts_router.js.coffee

class Voice.Routers.Posts extends Backbone.Router
        routes:
                '': 'index'
                ':id': 'show'
        initialize: ->
                @collection = new Voice.Collections.Posts()
                @collection.fetch()
        index: ->
                view = new Voice.Views.PostsIndex(collection: @collection)
                $('#container').html(view.render().el)
        show: (id) ->
                $("#post-#{id}").modal('show')

There are no errors in the js console, the modals just don’t seem to appear.
each post has a modal block with an html id field equal to “post-(the posts id)”

Any help is much 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-14T21:43:46+00:00Added an answer on June 14, 2026 at 9:43 pm

    This sounds very similar to a lot of SO questions on Bootstrap modals and using Backbone. Checkout this solution from Dereck Bailey,

    http://lostechies.com/derickbailey/2012/04/17/managing-a-modal-dialog-with-backbone-and-marionette/

    // the template
    <script id="modal-view-template" type="text/html">
      <div class="modal-header">
        <h2>This is a modal!</h2>
      </div>
      <div class="modal-body">
        <p>With some content in it!</p>
      </div>
      <div class="modal-footer">
        <button class="btn">cancel</button>
        <button class="btn-default">Ok</button>
      </div>
    </script>
    
    // the html has only one modal div
    <div id="modal"></div>
    
    
    // inside your show router function
    var view = new MyView();
    view.render();
    
    var $modalEl = $("#modal");
    
    $modalEl.html(view.el);
    $modalEl.modal();
    

    His explanation is,

    The core of the problem that people run in to when using a modal
    dialog is that the modal plugin removes the DOM element that wraps the
    modal, from the DOM. It usually gets added to some special holding
    location where the modal plugin can guarantee that the element won’t
    be visible until the modal dialog is opened. I’m over-generalizing
    this a bit, but many of the modal dialogs work this way or in a
    similar manner.

    The problem that this usually causes is that a Backbone view will lose
    it’s event handling when the DOM element gets moved around by the
    modal dialog. When the modal dialog removes the view’s el from the
    DOM, the events configuration is lost because the DOM element has
    been moved or removed from the DOM and jQuery had to let go of the
    events. When the el is re-added to the DOM for displaying it as a
    modal, then, the events are not re-attached.

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

Sidebar

Related Questions

I am trying to generate unique IDs for each modal, as I will be
I'm trying to generate a report of the activities that users have done within
I am trying to write a view that will generate a report which displays
Background: I'm trying to produce dynamically generated Factsheets, where each Factsheet has a number
I'm trying to parse the rows in a table that I generate using Javascript
I'm trying to generate QR codes of each shop's url. For example, I have
I have this error when trying to generate the meta model with JOOQ: org.jooq.exception.DataAccessException:
I am trying to generate some code using Acceleo. I am constructing my model
Trying to generate JavaDocs for the Android lint-cli project on Mac 10.7 Keep getting
Im trying to generate a color gradient using ColdFusion. My current code below works

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.