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 ability to pass variables into isActivePath #6

Open
paulmolluzzo opened this issue May 7, 2014 · 3 comments
Open

Add ability to pass variables into isActivePath #6

paulmolluzzo opened this issue May 7, 2014 · 3 comments

Comments

@paulmolluzzo
Copy link

It'd be great to be able to pass in a user- or session-specific variable to test the path. For example, let's say I have the following paths:

  • /users
  • /users/:_id
  • /users/:_id/edit

And let's say the navigation is:

Home Users Ny Name

I'd like to make the "Users" link active for all 3 of the paths, except if I'm editing my own User account, then I want "My Name" to be active.

I tried doing something like this but it didn't work:

<li class="{{ isActivePath '{{ currentUser._id }}/edit' }}">

Is this already possible? Is this a limitation of Blaze/Handlebars?

TIA.

@xpressivecode
Copy link
Owner

@paulmolluzzo I'm not sure if you can call a helper from within a helper like that.

Sorry, I haven't been doing a lot of Meteor work lately and this stuff escapes me.

Do you know, as an alternative if you can call a helper from within a helper function (not inline, but the actual helper itself)? If so, you could wrap the isActivePath call and build out the regex string manually that includes the current user id.

@zimme
Copy link

zimme commented Aug 15, 2014

@paulmolluzzo Maybe you can create a helper on the template where you use isActivePath and let that helper build the string with currentUser

Template.test.helpers({
  'currentUserEditPath': function() {
    return Meteor.userId() + '/edit'
  }
});
<template name='test'>
  <li class="{{ isActivePath currentUserEditPath }}">
</template>

@Furqankhanzada
Copy link

@paulmolluzzo : i have the same issue i did this:

created a helper for that template :

isActiveUser : function() {
    if(Router.current().path.indexOf(this._id) !== -1){
        return true;
    }
}

and i have already an helper

UI.registerHelper('isTrue', function(context, option) {
    if(context)
        return option;
});

usage:

<a class="list-group-item {{isTrue isActiveUser 'select'}}" href="{{pathFor 'usersShow'}}">

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

4 participants