Changing the currentpage before render

Vote:
 

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

#46842
Jan 06, 2011 13:16
Vote:
 

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?

#46843
Jan 06, 2011 13:38
Vote:
 

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?

#46844
Jan 06, 2011 13:47
Vote:
 

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;
            }
        }
    }
    
#46845
Jan 06, 2011 13:57
Vote:
 

As David notes above, I think CurrentPage is simply writable. Just replace it with a different PageData object,

#46846
Jan 06, 2011 13:58
Vote:
 

thank you, 

i didn't realise it was writable... doh.

must look harder before asking :)

 

#46848
Jan 06, 2011 15:12
Vote:
 

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.

#46849
Jan 06, 2011 15:33
Vote:
 

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

 

#46851
Jan 06, 2011 15:55
* 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.