Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
PersonalizedData.Current["Favorites", CurrentPage.PageLink] = "true";
And the list you're building should only show personalized items of the type "Favorites", but also shows additional personalized data like the EPSUBSCRIBE key that is also part of this data.
The CurrentUser.UserData.PersonalizedPages gives you an array of all pages that has personalized data attached to them. It does not filter on the type of data (the key used to store it), it will simply return all of it.
What you need to do after you've got that PageReference array is to check if that page has a "Favorites" item.
if (CurrentUser.UserData["Favorites", pageRef] != null)
...
where the pageRef is each of the PageReferences in the array returned from PersonalizedPages.
So the code should look something like this:
if (PersonalizedData.Current == null)
return;
PersonalizedData userData = PersonalizedData.Current;
foreach (PageReference pageRef in userData.PersonalizedPages)
{
if (userData["Favorites", pageRef] != null)
{
bool isFav = bool.Parse(userData["Favorites", pageRef].ToString());
if (isFav)
// Do your thing
}
}
Haven't tested the code (I'm just jotting it down from memory and the SDK.) It shouldn't be too far off.
/Steve
if(PersonalizedData.Current["Favorites", CurrentPage.PageLink] == null) PersonalizedData.Current["Favorites", CurrentPage.PageLink] = "true";
And when i´m listing the Fovirets on an other template I use this code:if (PersonalizedData.Current != null) { plcBookmarks.Controls.Add(new LiteralControl("\n")); PageBase oPage = (PageBase)this.Page; PageData oPersonalizedPage; for (int j=0; j<=opage.currentuser.userdata.personalizedpages.length-1 j opersonalizedpage="oPage.GetPage(oPage.CurrentUser.UserData.PersonalizedPages[j]);" opage.currentuser.userdata.personalizedpages. lnkbtn="new" linkbutton lnkbtn.id="oPersonalizedPage.PageLink.ToString();" lnkbtn.click ="new" system.eventhandler removebookmark lnkbtn.text="CurrentPage.Property["Remove"].ToString();" plcbookmarks.controls.addnew literalcontrol>\n\n")); plcBookmarks.Controls.Add(new LiteralControl("\n\n")); } plcBookmarks.Controls.Add(new LiteralControl("" + oPersonalizedPage.PageName.ToString() + " "));
plcBookmarks.Controls.Add(lnkBtn);
plcBookmarks.Controls.Add(new LiteralControl("
\n"));
}
The problem is that this listing allso shows the pages I´m subscribed to. I understand this, so I did this another way:if(PersonalizedData.Current["Favorites"] != null) { plcBookmarks.Controls.Add(new LiteralControl("\n")); ArrayList alFavorites = StringToArrayList(PersonalizedData.Current["Favorites"].ToString()); for(int iCnt=0; iCnt<=alfavorites.count-1; icnt string tmpbm="(string[])alFavorites[iCnt];" pagedata pd="GetPage((PageReference)" alfavoritesicnt lnkbtn="new" linkbutton lnkbtn.id="pd.PageLink.ToString();" lnkbtn.click ="new" system.eventhandler removebookmark lnkbtn.text="CurrentPage.Property["Remove"].ToString();" plcbookmarks.controls.addnew literalcontrol>\n\n")); plcBookmarks.Controls.Add(new LiteralControl("\n\n")); } plcBookmarks.Controls.Add(new LiteralControl("" + pd.PageName + " "));
plcBookmarks.Controls.Add(lnkBtn);
plcBookmarks.Controls.Add(new LiteralControl("
\n"));
}
But this does not work at all. it stops at the first IF-statment. Does someone have a solution for this problem? /Emil