Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

How to display the member group name (title) on the front-end?


Go to End


3 Posts   2926 Views

Avatar
neilcreagh

Community Member, 136 Posts

28 June 2010 at 10:42pm

Hi, I want to display the member Group title on my template after a member has signed in rather than the member name. eg. "Acme Ltd." instead of "John Smith".

I tried to create a new public function getGroupName() , so that I can call it on my template like so $Member.GroupName - but I'm not having any luck with it.

Can anyone advise the simplest method to call this?

Avatar
Willr

Forum Moderator, 5523 Posts

29 June 2010 at 10:10am

I tried to create a new public function getGroupName() , so that I can call it on my template like so $Member.GroupName

Well that function would have to be on the Member class (or a decorated instance of a member). One thing you would have to consider is that members has multiple groups so you would be dealing with a set rather than 1 group instance.

In the template you could try

<% control Member.Groups %>
$Title
<% end_control %>

Avatar
neilcreagh

Community Member, 136 Posts

29 June 2010 at 9:00pm

A much better solution, thank you.