Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EpiServer how to get the Link URL of a specific page?

I need to bind the LinkURL of the Blog Page with a link button on the Start Page. What I did was actually found that Page ID and get a Page Reference using it.

PageReference BlogPageReference = new PageReference(21);

PageData BlogPage = GetPage(BlogPageReference);

var url = BlogPage.LinkURL;

This is pretty straight forward, but I'm not happy that the Page ID is hard coded. Is there a better way of doing this, like getting the Page by Page name? or any other way?

Thanks in advance :)

like image 655
user1408470 Avatar asked Sep 06 '13 10:09

user1408470


1 Answers

I would create a property on the start page of type "Page", which means the property will have the type PageReference. Then it's no longer hardcoded.

It's also common to move such "settings" properties to a separate Settings page type which is itself linked via a property from the root or startpage (which are constants).

Im writing from memory so excuse any mistakes in the code.

var startPage = DataFactory.Instance.Get<StartPage>(PageReference.StartPage);
var settingsPage = DataFactory.Instance.Get<SettingsPage>(startPage.SettingsPage);
var blogPageRef = settingsPage.BlogPage;

Where SettingsPage and BlogPage are defined

public virtual PageReference xxxPage {get; set; }

in your page type class.

like image 60
Andreas Avatar answered Nov 24 '22 07:11

Andreas