Developer forum

Forum » Development » Manipulate GroupList before render

Manipulate GroupList before render

Jonas Kæseler
Reply
Hi

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

 
Yury Zhukovskiy
Reply

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

 
Jonas Kæseler
Reply
Hi 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
 
Yury Zhukovskiy
Reply

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

 
Jonas Kæseler
Reply

Of course!

Just what I needed.
Thanks for the very good example

Best regards
Jonas

 
Jonas Kæseler
Reply

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

 
Kim Søjborg Pedersen
Reply
I get the "type or namespace name GroupTemplateExtender could not be found" what assambly reference do I need?
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply
I could be wrong, but I don't think this extender exists in the current version of Dynamicweb. It's there in DW 8, so I guess this is an upcoming feature.

Cheers,

Imar
 
Jonas Kæseler
Reply
I agree,

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