Getting Page Reference from URL

Vote:
 

A complete newbie question by I can't seem to find the answer to this...

How do I get a reference to a page by absolute URL, e.g. "/mysite/child/grand-child"

PageReference.ParseURL looks like the correct method, but what am I missing?

 

            var relUrl = "/CommittedQuitters/Today/Blow-Temptation/";
            
            //var pageRef = PageReference.ParseUrl(relUrl);
            //var pageByLoc = DataFactory.Instance.GetPage(pageRef);

var url = "/mysite/child/grand-child";
var pageRef = PageReference.ParseUrl(url); <-- returns PageReference.EmptyReference
var page = DataFactory.Instance.GetPage(pageRef);

 

This works, but i'd rather not have the base url specified...

var url = new UrlBuilder("http://localhost:17000/CommittedQuitters/Today/Blow-Temptation/");
object pageRef;
Global.UrlRewriteProvider.ConvertToInternal(url, out pageRef); 

 

Eventually I will end up with several sites and languages, so the tree structure would be like so for example, so ideally i'd like to be able to retrieve the reference relatively...

"/mysite1/en-gb/child/grandchild"
"/mysite1/fr-fr/child/grandchild"

"/mysite2/en-gb/child/grandchild"
"/mysite2/it-it/child/grandchild"

"/mysite3/en-gb/child/grandchild"
"/mysite3/es-es/child/grandchild"

 

The way we have been replicating sites for testing purposes is just to copy paste/paste the node and setting the pageStartId in <siteSettings> web.config... waiting for our enterprise license so I may be completely wrong in the above so let me know.

 

Let me know if you need info.

thanks

Kam

#44891
Oct 19, 2010 19:20
Vote:
 

Hi,

I think you should/could use PermanentLinkUtility.GetPageReference() to get the PageReference from your url.

About the license, you don't need to wait, just order partner developer licence at license.episerver.com and you should get it automatic.

Regards Per

#44896
Oct 20, 2010 10:30
Vote:
 

Actually, it is the demo license which is sent automatically right away.

The partner developer license order is handled manually by EPiServer in your country, but they usually send it quick (within the hour) if you order within the business hours :)

#44901
Oct 20, 2010 11:02
Vote:
 

I have a developer license and this is sufficient for the moment, since it allows me to play around and figure out show to to things in EpiServer (I've previously worked in Sitecore so trying to figure out the differences). We have partner licenses being organised.

PermanentLinkUtility.GetPageReference() seems to require the fully qualified url with domain name, e.g.

var url = new UrlBuilder("http://localhost:17000/mysite/child/grand-child");
var pageRef = PermanentLinkUtility.GetPageReference(url);

 

Mmm, not sure if I am looking at this incorrectly. Obviously I can add in domain dynamically to build up the URL, but how do you guys get a reference to page by path when you don't know the ID... Does my logic look correct or is there another way to do this?

 

thanks

Kam

#44902
Oct 20, 2010 12:34
Vote:
 

Also, common localized text seems to be stored in xml files on disk (/lang/lang_EN.xml). Is it possible to move these from xml file into EpiServer tree instead. Current situation means these have to be edited by developers and when creating a new version of the site these will need to be replicated (and I have no idea how to do these when we have 2 sites both using english, but need slightly different text)

For example:

UK -> EN (en-gb)
Malaysia -> Malay (ms-my) + en-gb

If i could get this into the tree the site editors could change them as required and the common control text could be loaded relative to the site node.

I notice that episerver uses the text from these lang files like so. These seems very ASP.NET globalization-esque...

<EPiServer:Translate runat="server" Text="/profile/login/password" />

Is there a way using a episever control to retrieve text from a page/template and output to the user, without using a <asp:literal /> control and setting in the code behind?

#44931
Oct 21, 2010 12:36
Vote:
 

Ok, I have found the following control does what I need:

<EPiServer:Property runat="server" PropertyName="Intro" PageLink="961" />

But again, the PageLink ID needs to be specified, either here or setting it via CodeBehind. in SiteCore there is the equivelant tag, but notice we can specifiy the datasource, so point it at which ever page/template where we want the fieldname to be retrieved from:

<sc:FieldRenderer runat="server" FieldName="Intro" DataSource="/sitecore/content/ReferenceData" />

Why does Sitecore seems so much more flexible in its approach and use of XPath expressions. Surely you shouldn't have to bring in developers everytime you want to change common text? Argh!

#44943
Oct 21, 2010 14:50
Vote:
 

Hmmm, many questions in the same thread...

Well, here are some answers:

  •  To translate a path that leads to an internal page, i.e. a page in the current instance of EPiServer CMS you use PermanentLinkUtility.GetPageReference("/en/foo/faa/forum"). You can then create an instance of a PageData object by writing PageData pd = new PageData(myPageReference);
  • To render a page property value for the current page that is in scope you can use the EPiServer:Property web control. You don't have to set the PageLink attribute for the web control since the control will know the current page by using the CurrentPage property in the PageBase base class. If you take a look in code-behind you will find that the class inherits from TemplatePage, which in turn inherits from EditPage, SimplePage, PageBase and System.Web.UI.Page. PageBase gives you the reference to CurrentPage and the web controls will be able to get the page property value by using the PropertyName-attribute. Just make sure to spell the property name correctly.
  • The EPiServer CMS globalization lang files shoul contain "static" text that should be used by buttons, labels, etc. You should not put these text in the web site structure. When you create pages you can enable the globalization support and create pages that corresponds to each language, bu with sort of or the same web site structure. You can reach localized texts from code-behind by using the LanguageManager.Instance.Tranlate("XPath expression") syntaxt.
  • EPiServer CMS is not based on XML like SiteCore so you'll have to grasp the concept och Page Type, Pages and Page Templates.

Regards,
    Dan 

#45638
Nov 11, 2010 13:52
Vote:
 

Thanks Dan, I am learning more and more about EpiServer and differences in Sitecore... not entirely happy with the way it works but it is just different to Sitecore...

I've figured out most of what I need to do. Do you have any more information/article on the XPath selectors? Is it only only available for  LanguageManager.Instance.Tranlate() or for other methods also, like PermanentLinkUtility.GetPageReference or traversing from CurrentPage?

#45751
Nov 16, 2010 13:18
Vote:
 

To clarify, the xpath expressions used with the Translate method are typically used for template specific text. Page specific data is stored in the page, accessed by a PageData instance, typically the CurrentPage property to get the page currently being rendered. Either you use the Property control (which as mentioned, uses CurrentPage unless you specify differently) or by reading it from the PageData and displaying it in a literal etc.

In most cases you don't even have to think about the language of the PageData as you code, the correct language version will be selected for you depending on the globalization rules (url, users preferred language, fallback languages etc). The same goes for the Translate control / Translate method.

If you have reference data that is not static (say only some editors have the right to update it, but all editors should be able to display the data on a page) you could use Dynamic Content, or a system similar to what Deane described in his blog post: http://world.episerver.com/Blogs/Deane-Barker/Dates/2010/11/Simple-Token-Replacement/

I don't think I have ever needed to go from URL to PageData "manually" and that and the first time I got the question was only a few weeks back. So something tells me there is probably a more EPiServeresque way to do what you want to do. In what situations do you have the need to find the PageData corresponding to an URL?

#45756
Nov 16, 2010 14:13
Vote:
 

Thanks, the Dynamic Content will definitely be handy. I've also been playing around with PageData, XML files and localisation and certainly am able to work around "work around" most things for the moment.

The example that I am specifically thinking about... We have several websites on the same instance of EpiServer (using Enterprise licence). We have custom logic in our code that requires certain settings on a per site basis.

-Root Folder
- Site 1
-- Settings
-- Page 1
-- Page 2
- Site 2
-- Page 1
-- Page 2

Since EpiServer seems to be primarily based around Page ID's, how do I reference the Settings page for each site? I know what site I am running in from the Page Start ID (set in <site> in config)... I guess I could use a hash of Start Page URL + Settings and then use PermanentLinkUtility.GetPageReference(), but that somehow seems wrong...

For the moment I have a property set on the Start Page, and select the config for each specific site. There are certain changes we need to make when rolling out a new site, and this is relatively minor, so it may be that this goes in the checklist of things to do...

 

thanks

#45761
Nov 16, 2010 15:25
Vote:
 

There is a property type called Page. Either put such a property on the start page or use a dynamic property (!= dynamic content) to point to the settings page used in each part of the page tree. Or just store the settings you need on the start page (you can create a special tab for it and access control that tab). This is the typical way to store configuration that (at least some) editors need to be able to change. Maybe this is what you did, in that case I suggest you keep that solution unless there is a problem with it?

You can always get the start page by PageReference.StartPage. So you can construct the PageData by calling var startPage = DataFactory.Instance.GetPage(PageReference.StartPage). Then you can get your settings properties from that page, or if you choose to store them on a separate page you get the reference to that page from the start page by var settingsPageRef = startPage["MySettingsPageProperty"] as PageReference, then use DataFactory to get that second page and read its properties.

#45762
Nov 16, 2010 15:33
Vote:
 

Thanks Magnus. Yes, I did what you suggested in the first part of the answer (by using a POage property). That seems to solve the problem and works well. I was trying to go for a fully relative path based solution, but since this is one a very quick change, I don't think it is worth spending any time on or over complicating.

Was just making sure that there wasn't an easier way of doing what I wanted to achieve (and that it was correct). Having the setting in a separate tab also sounds like a good idea.

Kam

#45766
Nov 16, 2010 16:57
Vote:
 

If you want something more relative to the page tree you can use a dynamic property. A dynamic property is inherited down the page tree, but can be redefined at any level (and then inherited from that level instead). If you use a dynamic property to point to your settings page you can use different settings pages in different subtrees and not just one settings page per site.

#45768
Nov 16, 2010 17:30
Vote:
 

Thanks. I'll have another read through the link you gave and read up more on dynamic properties. For now the current set up works fine. In reality we need to make other config changes, have images re-cut, translate pages etc etc when launching a new site, so really changing one property is no big deal.

I'll bear this in mind when I refactor the code next though.

thanks again

#45769
Nov 16, 2010 17:38
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.