How do I display a specific article (page) ?

Vote:
 
I'm wondering how I should go about to display a specific article (page). Scenario ------------ The page type FrontPage has a property called 'selectedArticle' of the type Page. Here the user may select any article from the website. In my Default.aspx file I make space for this article to be displayed. It will show PageName, MainIntro and an Image. Now, I do not want to use PageList or NewsList since this is not a PageDataCollection, but simply PageData. So how do I go about this problem? Below are some solutions I have come up with so far. Possible solutions - 1 ----------------------- You crate a function called e.g. getArticle() which returns PageData.

<%=((episerver.core.pagedata)getarticle())["pagename"]%>

" alt="" class="image floatLeft" /> ((EPiServer.Core.PageData)getArticle())["MainIntro"]%> Les mer
The problem here is that you call the getArticle() function at least 5 times (when debugging it actually called it 10 times). So that is not very efficient. Possible solutions - 2 ----------------------- I create a PageDataCollection and use GetChildren to populate it. Then delete all children except the one I have referenced in selectedArticle property. PageData pd = GetPage(new PageReference(CurrentPage.Property["articleRotation"].ToString())); PageDataCollection pdc = GetChildren(pd.PageLink); foreach (PageData data in pdc) { if (pd.PageLink != data.PageLink) pdc.Remove(data); } return pdc; I have not tested this code, so I don't know if it works.
#13276
Nov 21, 2007 11:15
Vote:
 
PageDataCollection pdc = GetChildren(pd.PageLink); is wrong Correct is PageDataCollection pdc = GetChildren(pd.ParentLink); And it works fine. But it still would be nice to be able to do it without using PageList.
#15564
Nov 21, 2007 13:43
Vote:
 
I don't really understand your concerns regarding solution 1. You say the method is called 10 times when you debug, perhaps you have AutoEventWireup set to true and still bind to events in code-behind? 5 calls to a method really isn't a problem, although this might be slightly faster: CODE BEHIND: //local variable to hold the page data of the article: private PageData mArticleData; //Property to return the pagedata: protected PageData ArticlePage { get { //Load the page once and store in local variable if(mArticleData == null) mArticleData = GetPage((PageReference)CurrentPage.Property["articleRotation"]); return mArticleData; } } ASPX:

]]>

<%=ArticlePage["MainIntro"]%> Les mer This way you only fetch the pagedata once and use a property to access it from the aspx. Don't worry about calling the property 5 times to get the pagedata object, it's very fast.
#15565
Nov 22, 2007 10:31
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.