Copied to clipboard

Flag this post as spam?

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


  • Biagio Paruolo 1618 posts 1910 karma points c-trib
    Apr 12, 2016 @ 15:39
    Biagio Paruolo
    0

    How to build link rel="alternate"?

    Hi,

    I've a multi language site with 3 main roots ( each for a language ) that is it, en, de ( it, en and de are the root name too ). The en and de are copied from it ( with linked option on ).

    So, How to build the alternate link?

    Thank you.

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Apr 12, 2016 @ 17:05
    Ismail Mayat
    0

    Biagio,

    You can use the relations service. If you copied the sites with linked option checked then there will be a relation in the db. So in your partial / template you can for current page do:

                    var relationServce = Services.RelationService;
    
                IEnumerable<Relation> alternate = relationServce.GetByParentId(nodeId);
    

    More information here

    https://our.umbraco.org/Documentation/Reference/Management/Services/RelationService

    I had to do something very similar in fact its due to go live very soon although its for v6.

  • Biagio Paruolo 1618 posts 1910 karma points c-trib
    May 17, 2016 @ 06:51
    Biagio Paruolo
    0

    Which are the methods of relation object?

  • Biagio Paruolo 1618 posts 1910 karma points c-trib
    Apr 12, 2016 @ 18:22
    Biagio Paruolo
    0

    Thanks. How to add a new page? Must be added to parent tree parent site and then Umbraco create the copy or not?

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Apr 13, 2016 @ 08:29
    Ismail Mayat
    0

    Biagio,

    I think there is a component in nupickers package that will let you create relations. Or you can as you say create in parent then copy with relate.

    Regards

    Ismail

  • Craig100 1136 posts 2523 karma points c-trib
    May 27, 2016 @ 08:33
    Craig100
    102

    Hi Biagio,

    Happy to share this Macro for creating the hreflang tags. The only requirement is that all pages are copied from the same, original so the parent is the same for everything. So you'd create a new page in the original site and copy it out to another site to maintain the relationship tree:-

    @using Umbraco.Core;
    @using System.Linq;
    
    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @{
    
        // get a reference to the relation service
        var rs = ApplicationContext.Current.Services.RelationService;
        // get a list of all relations caused by copying from the current node
        var copies = rs.GetByParentId(Model.Content.Id).Where(f => f.RelationType.Alias == "relateDocumentOnCopy").ToList();
        // if this is the copied page see, if it is related to an original page
        var originals = rs.GetByChildId(Model.Content.Id).Where(f => f.RelationType.Alias == "relateDocumentOnCopy").ToList();
    
        //there should only be one original
        var originalRelation = originals.FirstOrDefault();
    
        // If there are no originals but there are copies then this is the original so list out copies   
        if (originalRelation == null) {
            if (copies.Any()) {
                foreach (var copyRelation in copies) {
                    // write out each node copied from this original
                    var copiedNode = Umbraco.TypedContent(copyRelation.ChildId);
                    if (copiedNode != null) {
                        <link rel="alternate" href="@copiedNode.Url" hreflang="@copiedNode.GetCulture().ToString().ToLower()">
                    }
                }
            }
        <link rel="alternate" href="@Umbraco.TypedContent(Model.Content.Id).Url" hreflang="x-default">
        }
    
        // If there is an original, then we are on a copy. List out the copies of it's original except this copy
        if (originalRelation != null) {    
            var theSiblings = rs.GetByParentId(originalRelation.ParentId).Where(f => f.RelationType.Alias == "relateDocumentOnCopy").ToList();
            foreach (var copyRelation in theSiblings) {
                // write out each node copied from this original
                var copiedNode = Umbraco.TypedContent(copyRelation.ChildId);
                if (copiedNode != null) {
                    if (copiedNode.Id != Model.Content.Id) {
            <link rel="alternate" href="@copiedNode.Url" hreflang="@copiedNode.GetCulture().ToString().ToLower()">
                    }    
                }
            }
            // List out the original
            <link rel="alternate" href="@Umbraco.TypedContent(originalRelation.ParentId).Url" hreflang="@Umbraco.TypedContent(originalRelation.ParentId).GetCulture().ToString().ToLower()">
            <link rel="alternate" href="@Umbraco.TypedContent(originalRelation.ParentId).Url" hreflang="x-default">
        }
    }
    

    Hope this helps

    Craig

  • Biagio Paruolo 1618 posts 1910 karma points c-trib
    Nov 28, 2016 @ 14:03
    Biagio Paruolo
    0

    I suggest for SEO to change from Url to UrlAbsolute()

  • Biagio Paruolo 1618 posts 1910 karma points c-trib
    Nov 28, 2016 @ 11:37
    Biagio Paruolo
    0

    Hi,

    it works. I create a Partial Views and included into the of the main view. Thanks

  • Dan Evans 631 posts 1018 karma points
    Mar 22, 2017 @ 14:13
    Dan Evans
    0

    Would it be better to create a new relationship type rather than using relateDocumentOnCopy - although it means manually adding all the relations it reduces the problem of inaccurate relations being generated when a page is copied within a language or for testing purposes.

    Just wondering what people's thoughts are on this?

  • Gerhard Grossberger 55 posts 179 karma points
    Jun 22, 2017 @ 14:16
    Gerhard Grossberger
    0

    From a technical point of view, maybe - but as an editor in umbraco I´d like to have the simplicity of just copying the page and it is automatically linked. We added a simple interface to umbraco where you can manually add / remove these relations from the GUI. If we can find the time we will add this as a package.

  • Cristhian Amaya 52 posts 423 karma points
    Apr 23, 2018 @ 06:12
    Cristhian Amaya
    0

    Hey! You might want to check this out: https://our.umbraco.org/projects/backoffice-extensions/linked-pages/

    I haven't tried it, but it's been in my radar for some time.

Please Sign in or register to post replies

Write your reply to:

Draft