Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimized code: Partial can’t be found when template is invoked with _.map #247

Open
Haraldson opened this issue Jan 28, 2016 · 2 comments

Comments

@Haraldson
Copy link

Optimized: Partials works nicely, unless they’re invoked from a template that is in turn invoked from _.map.
Unoptimized: Partials works no matter the context they’re in.

Am I supposed to bind my compiled template somehow, and if so, to what context?

Example given below

view.js

define(
    ['marionette', 'hbs!./template', 'hbs!./accepted-sources-template'],
    function(Marionette, Template, AcceptedSourcesTemplate)
    {
        return Marionette.ItemView.extend(
        {
            template: Template,

            setAcceptedSources: function()
            {
                // This here doesn’t work when code has been optimized
                var acceptedSources = _.chain(this.wrapper.sources)
                    .map(AcceptedSourcesTemplate)
                    .compact()
                    .value()
                    .join(',');

                this.$el.trigger('droppable:options:set', { accept: acceptedSources });
            }
        });
    }
);

accepted-sources-template.hbs

{{~#each operations~}}
    #panel-right .aggregate[data-source*="{{>type-sub-type-operation type=../type sub_type=../sub_type operation=this}}"] > div,#panel-right .results[data-source*="{{>type-sub-type-operation type=../type sub_type=../sub_type operation=this}}"] > ol > li{{~#unless @last~}},{{~/unless~}}
{{~/each~}}
@SlexAxton
Copy link
Owner

This definitely sounds like a context problem. Maybe you can do a {{log this}} in each mode to figure out what the context is?

@Haraldson
Copy link
Author

{{log this}} returns the correct attributes in all the templates.

The weird thing is that I can use other partials without any problems at all.

{{! The one causing problems – always called from inside a loop, thus the ../ and the this }}
{{>type-subtype-operation type=../type sub_type=../sub_type operation=this}}

{{! This one’s playing along nicely }}
{{>image image=image alt=title}}

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

No branches or pull requests

2 participants