Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dave de Moel 122 posts 574 karma points c-trib
    Aug 14, 2015 @ 11:54
    Dave de Moel
    0

    Multilingual site, how to get url to specific page

    Hey guys,

    I am having a problem with getting the url to a specific page in a partial view. The page in question has a version for each language and per language I need to the url in the partial view to change accordingly. How can I do that?

    Currently my structure of the site looks like this:

    NL
    - Pagina
    EN
    - Page
    

    Pagina and Page are both the same page, but with a different name. Currently I get the url for both pages by using the document type as a reference for findign them as the DT is unique, but as soon as it is not unique anymore I will have a problem. How can I make the url work? Setting it in a document property is NOT an option.

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Aug 14, 2015 @ 13:02
    Dave Woestenborghs
    0

    Can you post your code that can help. Probably needs some changes in the logic on how you retreive the page.

    Dave

  • Dave de Moel 122 posts 574 karma points c-trib
    Aug 14, 2015 @ 13:14
    Dave de Moel
    0

    Currently I do this:

    var homePage = CurrentPage.AncestorsOrSelf(1).First() as IPublishedContent;
    var productPage = homePage.Children.FirstOrDefault(c => c.DocumentTypeAlias == "ProductPage");
    

    Which of course is not ideal, as I will have a problem as soon as I introduce multiple pages with the same document type.

    I am currently changing it to a configurable property in the languages root node so that it will at least not break when I introduce more pages. However, the URL's should not be configurable by the client, so it really is just a 'need to work asap' solution.

    var homePage = CurrentPage.AncestorsOrSelf(1).First() as IPublishedContent;
    var pageId = homePage.GetPropertyValue<int>("mijnOmgevingPicker");
    Node node = new Node(pageId);
    
  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Aug 14, 2015 @ 13:22
    Dave Woestenborghs
    0

    you can also do something like this

    var homePage = CurrentPage.AncestorOrSelf("DocTypeOfHomePage")as IPublishedContent;
    

    This will return the homepage of the current site tree you are in. Or are your language nodes under your homepage ?

    Dave

  • Dave de Moel 122 posts 574 karma points c-trib
    Aug 14, 2015 @ 13:33
    Dave de Moel
    0

    The homepage is not the problem, that part works flawlessly. The problem is that I don't want to have to rely on the document type of the subpages being unique.

    Here is a more clear example of what I need.

    In the header of the website, when logged in there is a message: "You are currently logged in as [name]", where [name] is a link to a profile page (called 'My Collections'). This profile page, just like all other pages, is a different language depending on the language you have set. And the URL also changes depending on the language.

    Dutch: 'http://example.local/mijn-collecties/' German: 'http://example.local/de/meine-sammlungen/' Italian: ""http://example.local/it/le-mie-collezioni/

    So I can not get the page from the content tree by name, and doing it by document type is a bad solution because it might not be unique.

    Normally, for example when making a multilingual navigation, I can just loop through the childs of the root node for the current language, but in this case it is a single url. I am not trying to find a way to uniquely identify the content node from the tree, so I can make a dynamic (as far as language is concerned) url.

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Aug 14, 2015 @ 13:43
    Dave Woestenborghs
    0

    So your site has a structure like this I think

    Home
    - NL
    -- Pagina
    - EN
    -- Page
    - FR
    -- oh la la
    

    Is that correct ?

  • Dave de Moel 122 posts 574 karma points c-trib
    Aug 14, 2015 @ 13:47
    Dave de Moel
    0

    Not entirely. There is not a global Homepage, there is rather a homepage per language: Content structure

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Aug 14, 2015 @ 13:56
    Dave Woestenborghs
    0

    If you don't want to find the page by a query the only option is to set a picker for it on the homepage.

    But I see you already figured that out.

    Dave

  • Dave de Moel 122 posts 574 karma points c-trib
    Aug 14, 2015 @ 14:17
    Dave de Moel
    100

    Then I am afraid I have to live with that until I have developed a proper solution. Just a bit to bad there is not some property that is unique per site, but does not change if you copy the website, would be super useful, as that would allow me to query it, but also guarantee that the proper page is Always taken.

Please Sign in or register to post replies

Write your reply to:

Draft