Developer forum

Forum » Development » Extender/Subscriber: Getting product group meta information

Extender/Subscriber: Getting product group meta information

Søren Jakobsen
Reply

Hi community,

I'm trying to change the page meta information on a productpage/list (Title and Description). Need to get meta information from product groups recursively. But which template extender or subscriber do i have to use?

Have tried the PageTemplateExtender but here it seems like I only can change the page title. Any ideas?

Thanks in advance.

 

Best regards

Søren


Replies

 
Nicolai Pedersen
Reply

Hi Søren

That would be duplicate content, and should be avoided. Better use the groupname if no title exists.

Anyways, in the master template or in a notification subscriber, you can do something like this:

@{ 

 string GetGroupTitle()

 {

 string groupid = Dynamicweb.Context.Current.Request.QueryString["GroupID"];

 if (!string.IsNullOrEmpty(groupid))

 {

 return GetProductGroupTitle(groupid);

 }

 return string.Empty;

 }


 string GetProductGroupTitle(string groupID)

 {

 string title = string.Empty;

 var group = Dynamicweb.Ecommerce.Services.ProductGroups.GetGroup(groupID, Dynamicweb.Ecommerce.Common.Context.LanguageID);

 if(group is object) {

 title = group.Meta.Title;

 if (string.IsNullOrEmpty(title))

 {

 foreach (var subgroup in group.ParentGroups)

 {

 if (string.IsNullOrEmpty(subgroup.Meta.Title))

 {

 title = GetProductGroupTitle(subgroup.Id);

 }

 }

 }

 }

 return title;

 }

}

Probably do it in a OnOutput Subscriber

[Subscribe(Dynamicweb.Notifications.Standard.Page.OnOutput)]

 public class PageOnOutputObserver : NotificationSubscriber

 {

 public override void OnNotify(string notification, NotificationArgs args)

 {

 if (args == null)

 return;


 //Add a tag to the template instance

 var onOutputArgs = (Dynamicweb.Notifications.Standard.Page.OnOutputArgs)args;

 onOutputArgs.template.SetTag("myTag", "some text");



 //Change expiration of the login cookie

 Dynamicweb.Environment.Cookie cookie = Dynamicweb.Context.Current.Request.Cookies["DW_ExtranetSessionCookie"];

 if (cookie != null)

 {

 cookie.Expires = System.DateTime.Now.AddMinutes(20);

 Dynamicweb.Environment.CookieManager.UpdateCookie(cookie);

 }


 }

 }

 

You must be logged in to post in the forum