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

{{outlet}} inside {{if}} = weird behavior #3929

Closed
Steve-OH opened this issue Dec 14, 2013 · 4 comments
Closed

{{outlet}} inside {{if}} = weird behavior #3929

Steve-OH opened this issue Dec 14, 2013 · 4 comments
Labels

Comments

@Steve-OH
Copy link

I'm having some trouble with a template where there are two {{outlets}} in an {{if}}, one inside the "then" branch and one inside the {{else}}:

{{if foo}}
    ...
    {{outlet}}
    ...
{{else}}
    ...
    {{outlet}}
    ...
{{/if}}

What happens is that everything starts out fine, but eventually the markup that's supposed to go into the {{outlet}} ends up being inserted twice.

A jsfiddle demonstrating the behavior is here: http://jsfiddle.net/Steve_OH/V5ztf/

Run the fiddle; you start out in Edit View. Click on any of the three names and you'll see them properly rendered into the outlet. Now click on the Thumbnail View link (for the purposes of this example, Thumbnail View looks just like Edit View, except the names are in reverse order and there is no secondary outlet). Click on one of the names. This takes you back to Edit View, and the name is rendered correctly into the outlet as before. Now click on a different name. All of a sudden, the name is rendered twice. Once you get into this "bad" mode, there doesn't seem to be a way to get out without reloading.

@marcioj
Copy link
Contributor

marcioj commented Dec 14, 2013

I think that isn't possible to use the same outlet, in one template. You can use for example:

{{outlet}} ... {{outlet "menu"}}

But not

{{outlet}} ... {{outlet}} or {{outlet "menu"}} ... {{outlet "menu"}}

Based on your fiddle, you can get the same behavior using the outlet outside of the if. Like this:

<script type="text/x-handlebars" data-template-name="peeps">
    <h2>Peeps</h2>
    <a href="#/thumbs">Thumbnail View</a> <a href="#/">Edit View</a>
    {{#if isEditorVisible}}
        {{#each peep in controller}}
            <p>{{#linkTo "peep" peep}}{{peep.description}}{{/linkTo}}</p>
        {{/each}}                
    {{/if}}
    {{outlet}}
</script>

Give a look http://jsfiddle.net/marciojunior/nUKyQ/

@Steve-OH
Copy link
Author

I can see how having two {{outlet}}s in the same scope could be a problem, but given that these two are effectively in different scopes, I don't see why the template compiler isn't smart enough to deal with it. After all, it's possible to nest {{if}}s and {{each}}es, so the compiler does have to have some notion of a "context stack."

By the way, I know I can move the {{outlet}} outside of the {{if}} in the jsfiddle example, but I can't in the real code, because in the real code the surrounding blocks are different. Imagine this:

{{if foo}}
    <div class="foo">
        <div>
            <p>{{outlet}}</p>
        </div>
    </div>
{{else}}
    <div class="bar">
        <h2>{{outlet}}</h2>
    </div>
{{/if}}

There isn't a practical way to move the {{outlet}} outside of the {{if}} in this case.

@wagenet
Copy link
Member

wagenet commented Dec 14, 2013

Looks like a duplicate of #3187.

@wagenet wagenet closed this as completed Dec 14, 2013
@Steve-OH
Copy link
Author

I wouldn't be surprised if the underlying cause is the same as in #3187, but the manifested behavior is actually the opposite; instead of a view disappearing when it shouldn't, in this case it's appearing when it shouldn't. So it's possible that it's a different issue.

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

No branches or pull requests

3 participants