3214 Posts in 848 Topics by 810 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 3748 Views |
-
if CurrentMember = [SOLVED]

4 October 2009 at 9:53pm Last edited: 5 October 2009 10:34am
I'm trying to do something I thought would be super simple, but I can't figure it out.
I'd like to show certain text in a template if the CurrentMember is a specific Security Group (ie. Franchisees).
Tried:
<% if CurrentMember = Franchisees %>,
<% if CurrentMember.inGroup(2) %>
and writing a simple functionTeach me your ways o wise ones
-
Re: if CurrentMember = [SOLVED]

5 October 2009 at 1:22am
Im not shure if this is the best approach, but I would do the following.
Create a method in Page_Controller:
function MemberGroupText(){
$member = Member::currentUser();
$sqlQuery = new SQLQuery();
$sqlQuery->select = array('GroupID');
$sqlQuery->from = array("Group_Members");
$sqlQuery->where = array("MemberID =".$member->ID);
$rawSQL = $sqlQuery->sql();
$result = $sqlQuery->execute();
$groupid = $result->first();
return _t('MEMBERGROUPTEXT.'.$groupid['GroupID'], 'Default text');
}create a language file in mysite/lang/ like en_US.php or nl_NL.php
$lang['en_US']['MEMBERGROUPTEXT']['2'] = 'Welcometext group 2';
$lang['en_US']['MEMBERGROUPTEXT']['3'] = 'Welcometext group 3';In your template simply call the method when logged in with :
<% if CurrentMember %>
$MemberGroupText
<% end_if %>In this way you always have a default text when a grouptext is not there and you can simply add textstrings for new groups in your language file..
-
Re: if CurrentMember = [SOLVED]

5 October 2009 at 6:48am Last edited: 5 October 2009 6:49am
Thanks for your time and effort.
I'm not sure I want to go thru the trouble of having a separate file like the en_US.php just to store 1 word or an empty string.
Allow me to elaborate,
I'm replicating the "You're logged in as Martijn - Log Out - Profile" (as seen at the top of this page) but there is one group that isn't allowed to change their profile. I have blocked access via the CMS to that page, but I'd like to hide the "Profile" link from that security group.
so something like:
<% if Group2 %>
You're logged in as $CurrentMember.FirstName -
<a href="Security/logout/">Log Out</a> -
<% else %>
You're logged in as $CurrentMember.FirstName -
<a href="Security/logout/">Log Out</a> -
<a href="edit-details-page">Profile</a>
<% end_if %> -
Re: if CurrentMember = [SOLVED]

5 October 2009 at 9:50am
<% control Member %>
<% if inGroup(2) %>
group 2
<% else_if inGroup(3) %>
group 3
<% end_if %>
<% end_control %>But in this way you only hide the links, you need to change the php code to disallow profile access..
They could go to the profilepage by entering the url.. -
Re: if CurrentMember = [SOLVED]

5 October 2009 at 10:33am Last edited: 5 October 2009 10:34am
"you need to change the php code to disallow profile access..."
I did this...Profile page > Access tab > Who can view this page > Only these people > I selected two groups so the 3rd group can't view the Profile page.I had to change to CurrentMember, Member wasn't returning anything. And the Else_if wasn't working (although I don't need it for my situation). Did a quick check in the forums and it seems that they're working on a patch to get an Else_if to work.
so the end result is this:
<% control CurrentMember %>
<% if inGroup(1) %>
message
<% else %>
alternate message
<% end_if %>
<% end_control %>THANK YOU!!
| 3748 Views | ||
|
Page:
1
|
Go to Top |


