@* list children pages from the current page (= Model) *@ @foreach (var page in homeNode.Children) { <div> <td><a href="@page.Url" class="mainlevel">@page.Name</a></td> </div> }
</tr> </table> </div>
i copied 'en' root to 'de' and checked 'Relate copied items to original' while copying, and managed hostnames for 'en' (enroot.local) and 'de' (deroot.local) root.
my problem is:
i must have top navigation like this:
enpage1 enpage2 enpage3 de
and
depage1 depage2 depage3 en
if i'm on enpage3 and click 'de' i have to go to depage3
but, i don't know how to add 'en' or 'de' to my present top navigation and how to create functionality for 'en' and 'de'.
this takes the current page id and the relation type. From the returned relation you should get a reference to the related page's id and so should be able to add the friendly url for the page based on its id
Hi Pacoss, you actually have a 2 things that need to be resolved, and there is a quick way and a more robust way.
The homeNode will either be 'en' or 'de' each of these have their own node id (eg 1234 and 5678) so in your code you can do something like
var langLabel = "en";
if (homeNode.Id == "1234")
{ // if you are in the ne site then the label should be de
langLabel = "de";
}
Next you have to find the related page, your code should be something lilke
// get all the relations based on the relation type relateDocumentOnCopyRelation[] currentPageRelations = Relation.GetRelations(Model.Id, RelationType.GetByAlias("relateDocumentOnCopy"));
// there should only be 1 relation but you should add in logic to choose the right node just in caseforeach (Relation rel in currentPageRelations)
{
// depending on if you are on en or de the related page could either be the parent or the child// set the related page id to the relations parent idint relatedPageId = rel.Parent.Id;
// if the current pages id is the same as the relations parent id then we need to set it to the child idif (rel.Parent.Id == Model.Id)
{
relatedPageId = rel.Child.Id;
}
}
Your final code should end up looking somethign like
var langLabel = "en";
if (homeNode.Id == "5678")
{
langLabel = "de";
}
string altLangUrl = string.Empty;
// get all the relations based on the relation type relateDocumentOnCopyRelation[] currentPageRelations = Relation.GetRelations(Model.Id, RelationType.GetByAlias("relateDocumentOnCopy"));
// there should only be 1 relation but you should add in logic to choose the right node just in caseforeach (Relation rel in currentPageRelations)
{
// depending on if you are on en or de the related page could either be the parent or the child// set the related page id to the relations parent idint relatedPageId = rel.Parent.Id;
// if the current pages id is the same as the relations parent id then we need to set it to the child idif (rel.Parent.Id == Model.Id)
{
relatedPageId = rel.Child.Id;
}
altLangUrl = umbraco.library.NiceUrl(relatedPageId);
}
<ahref="@altLangUrl">@langLabel</a>
Use the code as a starting point and then put in breakpoitns to see what values are coming back
of course i used your code but modified a little bit and here it is:
@using umbraco.cms.businesslogic.relation;
<div> @{ var homeNode = Model.AncestorOrSelf(2); var rootNode = @Model.AncestorOrSelf(); //Home string altLangUrl = string.Empty; // get all the relations based on the relation type relateDocumentOnCopy Relation[] currentPageRelations = Relation.GetRelations(Model.Id, RelationType.GetByAlias("relateDocumentOnCopy"));
// there should only be 1 relation but you should add in logic to choose the right node just in case foreach (Relation rel in currentPageRelations) { // depending on if you are on en or de the related page could either be the parent or the child // set the related page id to the relations parent id int relatedPageId = rel.Parent.Id; // if the current pages id is the same as the relations parent id then we need to set it to the child id if (rel.Parent.Id == Model.Id) { relatedPageId = rel.Child.Id; } altLangUrl = umbraco.library.NiceUrl(relatedPageId); }
@* list children pages from the current page (= Model) *@ @foreach (var page in homeNode.Children) { <div> <td><a href="@page.Url" class="mainlevel">@page.Name</a></td> </div> }
@* add language *@ @foreach (var page in rootNode.Children) { if (@page.Id != @homeNode.Id) { <div> <td><a href="@altLangUrl" class="mainlevel">@page.Name</a></td> </div> } }
Good to know you got it working, the only thing where this may fall down a little is if you decide to add another langugae to the site, but for your immediate needs it is looking good
add language to top navigation
hi
my site looks like this:
content
home
en
enpage1
enpage1sub
enpage2
enpage3
de
depage1
depage1sub
depage2
depage3
on home page you can choose 'en' or 'de'.
top navigation for 'en' looks like this:
enpage1 enpage2 enpage3
for that structure i created .cshtml file for top navigation and it works ok:
<div>
@{
@* cxounter for position *@
var position = 1;
var homeNode = Model.AncestorOrSelf(2);
}
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
@* list children pages from the current page (= Model) *@
@foreach (var page in homeNode.Children)
{
<div>
<td><a href="@page.Url" class="mainlevel">@page.Name</a></td>
</div>
}
</tr>
</table>
</div>
i copied 'en' root to 'de' and checked 'Relate copied items to original' while copying, and managed hostnames for 'en' (enroot.local) and 'de' (deroot.local) root.
my problem is:
i must have top navigation like this:
enpage1 enpage2 enpage3 de
and
depage1 depage2 depage3 en
if i'm on enpage3 and click 'de' i have to go to depage3
but, i don't know how to add 'en' or 'de' to my present top navigation and how to create functionality for 'en' and 'de'.
so i'd appreciate any help
thanks
Hi Pacoss, the first thing is to determine whether or not to display de or en, you should be able to do this based on the homeNode's id
Once you have the correct text displaying then you have to make sure you link it to the correctly related page, to do this you will need to use
umbraco.cms.businesslogic.relation.Relation.GetRelations
this takes the current page id and the relation type. From the returned relation you should get a reference to the related page's id and so should be able to add the friendly url for the page based on its id
Hope that helps
sorry but i'm new in umbraco and have no experience and don't know how to write this code ... if there is any example i'd be thankful
and if i'm on 'en' page, my homeNode is 'en', but there should be displayed 'de' in top navigation ...
Hi Pacoss, you actually have a 2 things that need to be resolved, and there is a quick way and a more robust way.
The homeNode will either be 'en' or 'de' each of these have their own node id (eg 1234 and 5678) so in your code you can do something like
Next you have to find the related page, your code should be something lilke
Your final code should end up looking somethign like
Use the code as a starting point and then put in breakpoitns to see what values are coming back
Hope it helps
Asif, thanks a lot for code.
of course i used your code but modified a little bit and here it is:
@using umbraco.cms.businesslogic.relation;
<div>
@{
var homeNode = Model.AncestorOrSelf(2);
var rootNode = @Model.AncestorOrSelf(); //Home
string altLangUrl = string.Empty;
// get all the relations based on the relation type relateDocumentOnCopy
Relation[] currentPageRelations = Relation.GetRelations(Model.Id, RelationType.GetByAlias("relateDocumentOnCopy"));
// there should only be 1 relation but you should add in logic to choose the right node just in case
foreach (Relation rel in currentPageRelations)
{
// depending on if you are on en or de the related page could either be the parent or the child
// set the related page id to the relations parent id
int relatedPageId = rel.Parent.Id;
// if the current pages id is the same as the relations parent id then we need to set it to the child id
if (rel.Parent.Id == Model.Id)
{
relatedPageId = rel.Child.Id;
}
altLangUrl = umbraco.library.NiceUrl(relatedPageId);
}
}
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
@* list children pages from the current page (= Model) *@
@foreach (var page in homeNode.Children)
{
<div>
<td><a href="@page.Url" class="mainlevel">@page.Name</a></td>
</div>
}
@* add language *@
@foreach (var page in rootNode.Children)
{
if (@page.Id != @homeNode.Id)
{
<div>
<td><a href="@altLangUrl" class="mainlevel">@page.Name</a></td>
</div>
}
}
</tr>
</table>
</div>
Good to know you got it working, the only thing where this may fall down a little is if you decide to add another langugae to the site, but for your immediate needs it is looking good
yes, you are right for adding another language, but this site is only in 2 languages.
anyway, thanks again.
is working on a reply...