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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:43:03+00:00 2026-06-07T13:43:03+00:00

I’m using Backbonejs for my app and I’m trying to add Facebook comments and

  • 0

I’m using Backbonejs for my app and I’m trying to add Facebook comments and like/send buttons to some of my views. I’m instantiating the JavaScript SDK before instantiating the Router object, like this :

// main.js  
require([ "Router" ], function (Router) {

// Facebook authentication
// Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));

  // Init the SDK upon load
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '302210766529054', // App ID
      channelUrl : '//'+window.location.hostname+'/channel', // Path to your Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });

   // If the user has auth'd the app, instantiate the router object.
    FB.Event.subscribe('auth.statusChange', function(response) {
            if (response.authResponse) {
                 // user has auth'd your app and is logged into Facebook
                FB.api('/me', function(me){
                    if (me.username) {
                        window.currentUser = me;
                        $('#username').html(window.currentUser.name);
                        new Router();
                        Backbone.history.start();
                    }
                });
            }
    });

}

});

I can easily use the windows.currentUser variable in any of the views called by the Router. However, when I add

<div class="fb-comments" data-href="http://mywebsite/i/#items/" data-num-posts="2" data-width="470"></div>

to one the templates called by a view in the router, the comments (nor the like/send) div doesn’t appear. When I add it to one of the static elements of the index.html file, it works fine.

Am I missing anything here?

EDIT

Here is my router and views code as it was before i post the question.

router.js
define(
[
'models/song',
'models/user',
'models/spotlight',
'models/user-playlist',
'views/spotlight-view',
'views/playlist-view',
'views/single-playlist-view',
],
function(Song, User, SpotlightModel,UserPlaylist, SpotlightView, PlaylistView, SinglePlaylistView){
    return Backbone.Router.extend({
        initialize: function(){
            window.songQue = new Array();

        },
        routes:{
            '': 'index',
            'spotlight': 'index',
            'playlists': 'allPlaylist',
            'playlists/:id':'onePlaylist',
        },

        index: function(){
            var spotlight = new SpotlightModel({id:1});
            var spotlightView = new SpotlightView({spotlight: spotlight});
            spotlight.fetch();
            $('.content').html(spotlightView.el);
        },

        allPlaylist: function(){
            $('.content').html('');
            var user = new User({id:window.currentUser.id});
            /*
             * once user details are fetched from the server,
             * loop through the arrays of their playlists and
             * render them in the template.
             */

            user.bind('change', function(){
                console.log(this);
                for(var i=0; i<this.get('objects')[0].playlists.length; i++){
                var playlistView = new PlaylistView({
                    playlist: user.get('objects')[0].playlists[i],
                    user: this.get('objects')[0]
                });
                $('.content').prepend(playlistView.el);
            }

            });
        },

        onePlaylist: function(playlist_id){
            var userPlaylist = new UserPlaylist({id:playlist_id});
            var singlePlaylistView = new SinglePlaylistView({playlist: userPlaylist});
            $('.content').html(singlePlaylistView.el);

        }
    });
}
   );



// single-playlist-view.js
define(
[
    'text!templates/single-playlist/single-playlist.html',
    'text!templates/single-playlist/single-playlist-details.html',
    'text!templates/playlist/song-row.html',
],
function(SinglePlaylistTemplate, SinglePlaylistDetailsTemplate, SongRowTemplate){
    return Backbone.View.extend({

        initialize:function(options){

            this.playlistTemplate = _.template(SinglePlaylistTemplate);
            this.playlistDetailsTemplate = _.template(SinglePlaylistDetailsTemplate);
            this.songRowTemplate = _.template(SongRowTemplate);
            this.playlist = options.playlist;

            $(this.el).prepend(this.playlistTemplate);
            this.playlist.bind('change', this.render, this);
            this.playlist.fetch();


        },

        render:function(){
            this.renderSongs();
            this.renderDetails();

        },

        renderSongs: function(){
            // Put the size of songs in a variable 
            var size = this.playlist.get('objects')[0].songs.length;
            // Extra loop just for the sake of filling the page.
            for(var j=0; j<5; j++){
                for(var i=0; i<size; i++){

                this.$("#song-row").prepend(this.songRowTemplate({
                    song: this.playlist.get('objects')[0].songs[i]
                }));
            }
            }
        },

        renderDetails: function(){
            this.$('.single-playlist-details').prepend(this.playlistDetailsTemplate({
                playlist: this.playlist,
                thumbnail: this.playlist.get('objects')[0].songs[0].song_thumbnail,
                total:this.playlist.get('objects')[0].songs.length,
            }));
        }

    });
}
  );
  • 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-07T13:43:04+00:00Added an answer on June 7, 2026 at 1:43 pm

    The backbone views will are being rendered after the Facebook API Call – at the stage when you make the Facebook call the element does not exist.

    You really want to do the Facebook call inside your Router in the route for the page you want to display the facebook API results.

    If its something that you want to display on every page – e.g. Username/Profile pic consider putting the code in a separate function eg initUserInfoView() and then call it from each route where you want to display the info.

    To be honest this stuff actually belongs in your View – the router should initialize and render the view, and the view is responsible for fetching from Facebook and displaying

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

Sidebar

Related Questions

I am trying to render a haml file in a javascript response like so:
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.