The relate on copy will create entries in the Relations Section of your site under the alias 'relateDocumentOnCopy'
The original page id will be stored as the 'parent' of the relation and the copy page id will be stored as the 'child' in the relationship.
So for example in your partial view:
@{
// 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 (copies.Any())
{
<h2>Copies</h2>
foreach (var copyRelation in copies)
{
// write out each node copied from this original
var copiedNode = Umbraco.TypedContent(copyRelation.ChildId);
if (copiedNode != null)
{
`// (you could check copiedNode.Path to see if it is located in the site you` want to link to)
<a href="@copiedNode.Url">@copiedNode.Name</a>
}
}
}
@if (originalRelation != null)
{
// write out the original node this page was copied from
var originalNode = Umbraco.TypedContent(originalRelation.ParentId);
<h2>Original</h2>
<a href="@originalNode.Url">@originalNode.Name</a>
}
How to use relation in Partial Views
Hello,
I don't find a response to my question into the doc or on the forum, but maybe i look wrong .
So this is my structure :
Homepage
I copy this structure with option "relate to original" for have a relation between page in different language. The structure is now like this :
Homepage
Accueil
So this is my question, how to make in partial view a link (href) for go to the relate page.
for example when i'm on the page about-us a link to page a-propos-de-nous ? I don't find how to make that.
An idea ?
Thanks in advance !
Paul
Hi Paul
You can use the RelationService to query relations setup on your site:
https://our.umbraco.org/documentation/reference/management/services/relationservice
The relate on copy will create entries in the Relations Section of your site under the alias 'relateDocumentOnCopy'
The original page id will be stored as the 'parent' of the relation and the copy page id will be stored as the 'child' in the relationship.
So for example in your partial view:
if that helps get you started ?
regards
Marc
Hey Marc !
Thank you so much, it helps me to continue.
I do not quite understand documentation
Thanks again
is working on a reply...