Does anybody know how to create a language selectbox that links to the same page in the selected language ?
Developer forum
E-mail notifications
Language selectbox
Posted on 04/05/2011 15:14:22
Replies
Nicolai Høeg Pedersen
Posted on 04/05/2011 15:18:54
eCommerce language or Dynamicweb language management ?
Posted on 04/05/2011 15:19:44
Dynamicweb Language Management
Nicolai Høeg Pedersen
Posted on 04/05/2011 15:49:12
Not possible out of the box. Will add it.
Until then:
Create 2 notifcation subscribers
Notifications.Standard.Page.AfterOutput
Dim masterid As Integer = 0
If Base.ChkInteger(PageView.Current.Area.Value("AreaMasterAreaID")) > 0 Then
masterid = Base.ChkInteger(PageView.Current.Area.Value("AreaMasterAreaID"))
Else
masterid = PageView.Current.Area.ID
End If
Dim myLangTemplate As Templatev2.Template = globalTemplate.GetLoop("Languages")
For Each myArea As Frontend.Area In PageView.Current.AreaCollection
If Base.ChkInteger(myArea.Value("AreaMasterAreaID")) = masterid Then
myLangTemplate.SetTag("Culture", Base.ChkString(myArea.Value("AreaCulture")))
myLangTemplate.SetTag("Name", Base.ChkString(myArea.Value("AreaName")))
End If
Next
globalTemplate is the argument you get in the notifcation.
Notifications.Standard.Page.Loaded
If Not String.IsNullOrEmpty(Base.Request("ID")) AndAlso Not String.IsNullOrEmpty(Base.Request("Culture")) Then
Dim p As Dynamicweb.Content.Page = Dynamicweb.Content.Page.GetPageById(Base.ChkInteger(Base.Request("ID")))
For Each p2 As Dynamicweb.Content.Page In p.Languages
If p2.Area.Culture = Base.Request("Culture") Then
HttpContext.Current.Response.Redirect("Default.aspx?ID=" & p2.ID, True)
Exit For
End If
Next
End If
Until then:
Create 2 notifcation subscribers
Notifications.Standard.Page.AfterOutput
Dim masterid As Integer = 0
If Base.ChkInteger(PageView.Current.Area.Value("AreaMasterAreaID")) > 0 Then
masterid = Base.ChkInteger(PageView.Current.Area.Value("AreaMasterAreaID"))
Else
masterid = PageView.Current.Area.ID
End If
Dim myLangTemplate As Templatev2.Template = globalTemplate.GetLoop("Languages")
For Each myArea As Frontend.Area In PageView.Current.AreaCollection
If Base.ChkInteger(myArea.Value("AreaMasterAreaID")) = masterid Then
myLangTemplate.SetTag("Culture", Base.ChkString(myArea.Value("AreaCulture")))
myLangTemplate.SetTag("Name", Base.ChkString(myArea.Value("AreaName")))
End If
Next
globalTemplate is the argument you get in the notifcation.
Notifications.Standard.Page.Loaded
If Not String.IsNullOrEmpty(Base.Request("ID")) AndAlso Not String.IsNullOrEmpty(Base.Request("Culture")) Then
Dim p As Dynamicweb.Content.Page = Dynamicweb.Content.Page.GetPageById(Base.ChkInteger(Base.Request("ID")))
For Each p2 As Dynamicweb.Content.Page In p.Languages
If p2.Area.Culture = Base.Request("Culture") Then
HttpContext.Current.Response.Redirect("Default.aspx?ID=" & p2.ID, True)
Exit For
End If
Next
End If
Posted on 04/05/2011 15:51:23
Thanks for the code sample!
This will do for now.
Kind Regards,
Emil
This will do for now.
Kind Regards,
Emil
Posted on 04/05/2011 17:54:29
The code sample does not work:
In the code sample you have:
Dim p As Dynamicweb.Content.Page = Dynamicweb.Content.Page.GetPageById(Base.ChkInteger(Base.Request("ID")))
For Each p2 As Dynamicweb.Content.Page In p.Languages
....
....
I do not seem to have a property "Languages" on the Dynamicweb.Content.Page class !
I checked version 19.2.2.1 and 19.2.2.3.
Help?
In the code sample you have:
Dim p As Dynamicweb.Content.Page = Dynamicweb.Content.Page.GetPageById(Base.ChkInteger(Base.Request("ID")))
For Each p2 As Dynamicweb.Content.Page In p.Languages
....
....
I do not seem to have a property "Languages" on the Dynamicweb.Content.Page class !
I checked version 19.2.2.1 and 19.2.2.3.
Help?
Nicolai Høeg Pedersen
Posted on 04/05/2011 18:00:58
Oh - new property not yet released...
Sorry.
You can do like this instead...
For Each p2 As Dynamicweb.Content.Page In Dynamicweb.Content.Page.GetPagesBySql(String.Format("SELECT * FROM Page WHERE PageMasterPageID = {0}", p.ID))
Sorry.
You can do like this instead...
For Each p2 As Dynamicweb.Content.Page In Dynamicweb.Content.Page.GetPagesBySql(String.Format("SELECT * FROM Page WHERE PageMasterPageID = {0}", p.ID))
Posted on 04/05/2011 18:16:21
Thanks! It works now.
If other people are interested in a C# version of this code, here it is:
( I changed the code a bit, so that it also includes language of the masterpage, i.e. that was missing from the above code sample)
[Subscribe(Dynamicweb.Notifications.Standard.Page.AfterOutput)] public class LanguageSelect_AfterOutput : NotificationSubscriber { public override void OnNotify(string notification, object[] args) { Dynamicweb.Templatev2.Template tpl = args[0] as Dynamicweb.Templatev2.Template; int iMasterID = PageView.Current().Area.ID; if (Base.ChkInteger(PageView.Current().Area.get_Value("AreaMasterAreaID")) > 0) iMasterID = Base.ChkInteger(PageView.Current().Area.get_Value("AreaMasterAreaID")); Dynamicweb.Templatev2.Template tplLangLoop = tpl.GetLoop("Languages"); foreach (object key in PageView.Current().AreaCollection.Keys) { Area myArea = PageView.Current().AreaCollection[key] as Area; if (Base.ChkInteger(myArea.get_Value("AreaMasterAreaID")).Equals(iMasterID) || Base.ChkInteger(myArea.ID).Equals(iMasterID)) { tplLangLoop.SetTag("Culture", myArea.get_Value("AreaCulture").ToString()); tplLangLoop.SetTag("Name", myArea.get_Value("AreaName").ToString()); tplLangLoop.CommitLoop(); } } } }[Subscribe(Dynamicweb.Notifications.Standard.Page.Loaded)] public class LanguageSelect_PageLoaded : NotificationSubscriber { public override void OnNotify(string notification, object[] args) { if (!String.IsNullOrEmpty(Base.Request("ID")) && !String.IsNullOrEmpty(Base.Request("Culture"))) { Dynamicweb.Content.Page p = Dynamicweb.Content.Page.GetPageById(Base.ChkInteger(Base.Request("ID"))); foreach (Dynamicweb.Content.Page p2 in Dynamicweb.Content.Page.GetPagesBySql(String.Format("SELECT * FROM Page WHERE PageMasterPageID = {0} OR PageID = {1}", p.ID, p.MasterPageID))) { if (p2.Area.Culture.Equals(Base.Request("Culture"))) { HttpContext.Current.Response.Redirect(string.Format("/Default.aspx?ID={0}", p2.ID), true); break; } } } } } Kind Regards, Emil
Posted on 04/05/2011 18:24:24
Another hint.
if you need the display name for the language/culture, add this to the language loop:
if you need the display name for the language/culture, add this to the language loop:
System.Globalization.CultureInfo ci = new System.Globalization.CultureInfo(myArea.get_Value("AreaCulture").ToString()); tplLangLoop.SetTag("DisplayName", ci.DisplayName); -Emil
You must be logged in to post in the forum