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

[Request] Ability to check if a given 'contentFor' has been set #17

Open
zvictor opened this issue May 3, 2014 · 1 comment
Open

[Request] Ability to check if a given 'contentFor' has been set #17

zvictor opened this issue May 3, 2014 · 1 comment

Comments

@zvictor
Copy link

zvictor commented May 3, 2014

Considering that

  • almost every time we use a contentFor we have a wrapper around it (usually a header, footer or just a div with some classes);
  • when there is no content for a given region, usually there is no reason to keep the empty wrapper there.
  • a wrapper with no content is obviously harder to hide than a wrapper that just does not exist.
    • Sometimes it can be considerable hard to hide the empty wrapper without screwing the rest of your css.

Than I infer that we should have a way to use some kind of if statement to check if we should add a region code with its wrapper inside our html.

That's an example to express my idea:

<template name="MyLayout">
  <h1>My Layout</h1>

  <div>
    {{> yield}}
  </div>

{{#if [THE FOOTER CONTENT HAS BEEN DEFINED]}}
  <footer>
    {{> yield region="footer"}}
  </footer>
{{/if}}
</template>

Is there a way to do it now? If not, is it possible for us to implement it, and what would be a good "syntax" for that?

@tmeasday
Copy link
Contributor

tmeasday commented May 4, 2014

Hi @zvictor - check out the pass-regions-as-arguments branch.

The API isn't totally decided yet, but as it stands, it adds 3 features:

  1. You can attach templates to regions via {{#Layout regionName='templateName'}} (rather than contentFor)
  2. You can check for defined regions via {{#if hasYield}}
  3. You can use "text" content (rather than templates) with {{yield region='regionName' text=true}}.

Give it a try. I'd love to hear feedback on any issues and also what you think about the API.

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