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

Add a helper to check whether a partial is defined #1948

Open
ReneZeidler opened this issue Jun 13, 2023 · 0 comments · May be fixed by #1953
Open

Add a helper to check whether a partial is defined #1948

ReneZeidler opened this issue Jun 13, 2023 · 0 comments · May be fixed by #1953
Labels

Comments

@ReneZeidler
Copy link

This was previously discussed here. The conclusion was that there currently is no way to check whether a partial is defined, so I'm making a feature request here.

This is mainly useful for inline partials, like the example from the docs.

If you define a partial layout like this:

<div class="nav">
  {{> nav}}
</div>
<div class="content">
  {{> content}}
</div>

it basically has 2 "template parameters" that are passed to the partial using inline partials:

{{#> layout}}
  {{#*inline "nav"}}
    My Nav
  {{/inline}}
  {{#*inline "content"}}
    My Content
  {{/inline}}
{{/layout}}

Now I want to make the nav parameter in my layout partial optional. I can use {{#> nav}}{{/nav}} to avoid an error if the partial is missing. But this will still leave the enclosing <div class="nav"></div> in the output. To avoid this, I need a way to check if the nav partial is defined, for example {{#if (partialDefined "nav")}}. Helpers also don't receive any information about existing partials, so implementing a custom helper for this isn't currently possible either.


In summary, I'd like to be able to do this:

{{#if (partialDefined "nav")}}
  <div class="nav">
    {{> nav}}
  </div>
{{/if}}
<div class="content">
  {{> content}}
</div>
{{#> layout}}
  {{#*inline "content"}}
    My Content
  {{/inline}}
{{/layout}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants