Search code examples
javascriptember.jsember-cli

Pass params to a view then to helper in Ember.js


I have 2 views that share a view and I am trying to pass variables between them to turn on|off various html segments. Is this possible? When I run console.log the view.showTitle variable = "view.showTitle" not 1 like it should be? Odd, right?

view 1 calls view 2 and passes param:

{{view "components/social" showTitle="1"}}

view 2 tries to pass this param to a helper function:

{{#variable-exists view.showTitle}}
  YES
{{else}}
  NO
{{/variable-exists}}

the helper being called:

export default function(elem,options) {
  if (Ember.isEmpty(elem)) {
    return options.inverse(this);
  } else {
    return options.fn(this);
  }
}

I am using the ember cli project to build my ember application.

Current setup at the time of this post:

DEBUG: -------------------------------
DEBUG: Ember      : 1.5.1
DEBUG: Ember Data : 1.0.0-beta.7+canary.b45e23ba
DEBUG: Handlebars : 1.3.0
DEBUG: jQuery     : 2.1.1
DEBUG: -------------------------------

Solution

  • Following these 2 guides a-way-to-let-users-define-custom-made-bound-if-statements and custom bound helpers I was able to adjust my shared views to use this instead of the standard #if statement. This should be more secure than just tossing an #if in there.

    <li>
        <a href="{{unbound view.varProductSocialBlog}}">
            {{#if-equal view.showDiv "true"}}<div>{{/if-equal}}<i class="fa fa-rss-square"></i>{{#if-equal view.showDiv "true"}}</div>{{/if-equal}}
            {{#if-equal view.showTitle "true"}}Blog{{/if-equal}}
        </a>
    </li>
    

    I am using the ember cli project to build my ember application.

    Current setup at the time of this post:

    DEBUG: -------------------------------
    DEBUG: Ember      : 1.5.1
    DEBUG: Ember Data : 1.0.0-beta.7+canary.b45e23ba
    DEBUG: Handlebars : 1.3.0
    DEBUG: jQuery     : 2.1.1
    DEBUG: -------------------------------