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 :)
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.
Where SettingsPage and BlogPage are defined
in your page type class.