Skip to content

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

@Haraldson

Description

@Haraldson

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~}}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions