Skip to content

Is it possible to render a partial without the parent scope? #1032

Closed
@aputinski

Description

@aputinski

I'm trying to treat partials as "components" that only have access to variables that were passed in as attributes — is this possible?

my-partial.hbs

<div class="my-partial">
  <!-- should only be displayed if it was passed in as an attribute -->
  {{#if name}}
    Hello, {{name}}
  {{/if}}
</div>

my-app.js

const data = { name: 'Adam' }

my-app.hbs

Hello, my name is {{name}} and is available in the template scope
{{> myPartial}}
{{> myPartial name="John"}}

Actual output

Hello, my name is Adam and is available in the template scope
<div class="my-partial>
  Hello, Adam
</div>
<div class="my-partial>
  Hello, John
</div>

Desired output

Hello, my name is Adam and is available in the template scope
<div class="my-partial"></div>
<div class="my-partial">
  Hello, John
</div>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions