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

1

7

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 :)

Jarrod answered 6/9, 2013 at 10:36 Comment(0)
D
10

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.

Donn answered 7/9, 2013 at 9:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.