Developer forum
E-mail notifications
Manipulate GroupList before render
How do I change groups in a GroupList before showing them to the user?
I was desperately looking for a GroupList.BeforeSort NotificationSubscriber similar to the one in the ProductList but unfortunately this doesn't seem to exist.
Are there any other ways to manipulate the list?
Jonas
Replies
Hi Jonas,
I confirm there is no such notification like “before sort” for group list.
I can recommend you try NavigationProvider, you already know this solution (http://developer.dynamicweb-cms.com/Forum/Development/NavigationProvider-Remove-menus.aspx?PID=48)
Finally you can try to use DataList module, type own SQL query and receive desired layout.
Kind Regards
Zhukovskiy Yury
Thanks for your reply.
Actually, what I need to achieve is the same as described in my other thread.
However, I'm not really sure that a navigation provider will work in my case - maybe I'm lacking imagination.
I need to show a list of Groups on my page. Each group will show Name,Image and a list of subgroups - the same features as the normal eCom catalogue - except that both the Groups and subgroups needs to be filtered according to the current users permissions.
Finally, when browsing a Group that has products, only the productlist is shown and not the groups (same as the standard eCom catalogue module)
BR
Jonas
Hi,
I have solution!
You need to create a group template extender and make permissions check as you wanted. In the extender you have access to current user and rendered group. If permission check is successful, then populate custom tag (Custom.CheckHasAccess in my example). Second, you need to change group list template and decorate group’s tags by “if defined” construction with your custom tag checking (see example).
Code of GroupTemplateExtender:
using Dynamicweb;
using Dynamicweb.eCommerce.Products;
namespace CustomModules1
{
public class GroupTemplateExtender1 : GroupTemplateExtender
{
public override void ExtendTemplate(Dynamicweb.Templatev2.Template template)
{
string userID = User.UserID.ToString();
string groupID = Group.ID;
string requiredUserGroup = "291";//example user group
//make permission check
//User.Groups contains array of groups where the user presents
bool condition = User.Groups.Contains(requiredUserGroup);
if (condition)
{
template.SetTag("Custom.CheckHasAccess", "true");
}
else
{
//nothing to do.
}
}
}
}
Group list template:
<ul id="grouplist" class="horizontal">
<!--@LoopStart(Groups)-->
<!--@If Defined(Custom.CheckHasAccess)-->
<li class="listitem<!--@Groups.LoopMod2-->" style="display:<!--@Custom.Visible-->">
<h3><a href="<!--@Ecom:Group.Link.Clean-->"><!--@Ecom:Group.Name--></a></h3>
<span class="shortdescription"><!--@Ecom:Group.Description--></span><br/>
</li>
<!--@EndIf(Custom.CheckHasAccess)-->
<!--@LoopEnd(Groups)-->
</ul>
Kind Regards
Zhukovskiy Yury
Of course!
Just what I needed.
Thanks for the very good example
Best regards
Jonas
Hi Yury
I cant find this extender anywhere.
I only have the "old" ProductTemplateExtenders etc.
I references the newest Dynamicweb.dll downloaded today and basically copy/pasted you code above. I think this should work.
Do you know what I'm missing?
Cheers
Jonas
Cheers,
Imar
The extender seems to be missing in DW7. I did not find any workaround, unfortunately.
BR
Jonas
You must be logged in to post in the forum