Can you expand on your requirement a little? CurrentPage is the PageData for the page in the CMS. It sounds like you might want to get the PageData from another page rather than "swap" it on page load?
ok,
I have a page that will be displayed to most people, but there might be another more appropriate page that can be displayed (based on login),
what i would like to do is continue using the <episerver:property> controls, but manipulate in code what the page episerver thinks is the currentpage.
I'm getting closer by overriding the CurrentPageLink property and using a local variable that i change on init.
does that make any sense?
I've not tried it myself but I'd inherit EPiServer.TemplatePage then override the CurrentPage. Something like the example code below should do the trick:
public class MyTemplatePage : TemplatePage
{
public MyTemplatePage()
: base()
{
}
public new virtual PageData CurrentPage
{
get
{
//Do some custom code here, with something like the below
if (condition == true)
{
return DataFactory.Instance.GetPage(new PageReference(9999));
}
else
{
return base.CurrentPage;
}
}
set
{
base.CurrentPage = value;
}
}
}
As David notes above, I think CurrentPage is simply writable. Just replace it with a different PageData object,
thank you,
i didn't realise it was writable... doh.
must look harder before asking :)
I've always thought this is a great example of how developer-friendly EPiServer is. 99% of other content management systems would never make that property writable. "It represents the current page!," they would say, "We can't let them change that! Think of the trouble they could cause!!"
When I found that CurrentPage was actually writable, I was amazed.
Although it seemed to work, the episerver:property must be still use base.CurrentPage as its not working,
I'm still having some success with the following, im just not sure what else might break because of it
private PageReference _currentPageLink;
public override PageReference CurrentPageLink
{
get
{
return _currentPageLink;
}
set
{
_currentPageLink = value;
}
}
protected override void OnInit(EventArgs e)
{
_currentPageLink = getCustomPageLink();
base.OnInit(e);
}
From that point on CurrentPage always uses my new version of the page
Hi,
Is there any way to change the currentPage before the page loads,
i have tried to set the currentPageLink on preInit but nothing happens,
Any pointers?
cheers