Posted on 25/10/2021 17:09:04
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);
}
}
}