Skip to content
This repository has been archived by the owner on Mar 26, 2018. It is now read-only.

When you create a view in a subfolder, the corresponding template in the subfolder isn't detected #275

Open
serv opened this issue Jul 14, 2014 · 1 comment

Comments

@serv
Copy link

serv commented Jul 14, 2014

tldr

When you have a view like views/subdirectory/new.js and a template like templates/subdirectory/new.ejs, the template isn't detected by the view. But when you have a view like views/no_subdirectory_new.js and a template like templates/no_subdirectory_new.ejs, the template is detected just fine.


Let me know if this bug isn't related to generator-backbone. I wasn't sure which project this bug is related to.

/*global define*/

define([
    'jquery',
    'underscore',
    'backbone',
    'templates',
    'linkModel'
], function ($, _, Backbone, JST, Link) {
    'use strict';

    var LinksNewView = Backbone.View.extend({

        /////////////////////// THIS LINE //////////////////
        template: JST['app/scripts/templates/link/new.ejs'],
        // I have the template in templates/link/new.ejs
        /////////////////////////////////////////////////////////////        

        tagName: 'div',

        id: '',

        className: '',

        el: '#main',

        events: {},

        initialize: function () {
            this.model = new Link();
            this.listenTo(this.model, 'change', this.render);
            this.render();
        },

        render: function () {
            // this.$el.html(this.template(this.model.toJSON()));
            this.$el.html(this.template(this.model));
        }
    });

    return LinksNewView;
});

This doesn't work. When I try adding debugger; in the initialize function, and check for this.template, I get undefined.

However, not using subdirectory will work.

/*global define*/

define([
    'jquery',
    'underscore',
    'backbone',
    'templates',
    'linkModel'
], function ($, _, Backbone, JST, Link) {
    'use strict';

    var LinksNewView = Backbone.View.extend({

        ////// THIS LINE ////
        template: JST['app/scripts/templates/link_new.ejs'],
        ///////

        tagName: 'div',

        id: '',

        className: '',

        el: '#main',

        events: {},

        initialize: function () {
            this.model = new Link();
            this.model.url = 'google.com';
            this.listenTo(this.model, 'change', this.render);
            this.render();
        },

        render: function () {
            // this.$el.html(this.template(this.model.toJSON()));
            this.$el.html(this.template(this.model));
        }
    });

    return LinksNewView;
});

When I check this.template in the initialize function, it returns the function that will be used to get the content of the template.

Any idea what the problem might be? If this isn't a bug for generator-backbone, which other repository should I file this bug? Thank you.

@revathskumar
Copy link
Member

Looks like bug within backbone generator, let me try to reproduce.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants