2012-11-13 16 views
1

擁有多語言網站,例如,通過多語言站點中的剃刀獲取基於當前節點的相關頁面

Content 
+UK Home 
    -About Us 
+US HOme 
    -About Us 

如何通過剃鬚刀根據英國「關於我們」的當前節點獲取美國「關於我們」頁面?美國網站使用關係從英國網站複製。

當訪問者訪問美國「關於我們」時,根據業務規則將訪問者重定向到英國「關於我們」。問題是我需要以編程方式獲取英國「關於我們」頁面的有效網址,並將訪問者重定向到該頁面。似乎Umbraco沒有太多的支持。例如,Umbraco關係僅適用於主頁級別。每個站點都有一個具有多個級別的樹節點。

任何想法,將不勝感激。

一把umbraco 4.10

回答

0

當您創建多語種網站你在副本中的「涉及複製的項目,以原有的」?或者頁面之間存在關係?

在Razor中,您應該能夠訪問Umbraco原生的Relation API。

事情是這樣的:

@using umbraco.cms.businesslogic.relation; 
@using umbraco.cms.businesslogic.member; 

@{ 
    RelationType relationType = RelationType.GetByAlias("relateDocumentOnCopy"); 
    Relation[] relations = Relation.GetRelations(Model.Id, relationType); 

    <h2>Relations</h2> 
    foreach (Relation relation in relations) 
    { 
... 
    } 
} 

我從這個論壇的帖子得到這個代碼基本上是:http://our.umbraco.org/forum/developers/razor/28103-Using-relations-with-razor

這裏有一個博客帖子上的關係API的更多信息:http://blog.hendyracher.co.uk/umbraco-relation-api/

而且,如果你有機會獲得一個付費的Umbraco.tv帳戶,這將有助於:http://umbraco.com/help-and-support/video-tutorials/developing-with-umbraco/relations/simple-document-to-document-relation/TVPlayer

2

我只需要figu使用7.2.6自己重新編寫...

因爲BeaverProj的答案並不完整,所以我認爲我會分享。

如果有人用較短的代碼來做同樣的事,那將會很好。

@{ 

var rs = ApplicationContext.Current.Services.RelationService; 
var currentPageId = CurrentPage.AncestorOrSelf().Id; 

var relations = rs.GetByParentOrChildId(currentPageId); 


     <h2>Relations</h2> 
foreach (Relation relation in relations) 
{ 
    if (relation.RelationType.Alias == "relateDocumentOnCopy") 
    { 
     // the relation has two ids... 
     // 1. parent 
     // 2. child 
     // we want the opposite one as the id above is for the current node 
     umbraco.NodeFactory.Node node; 

     if (relation.ParentId == currentPageId) 
     { 
      //get child 
      node = new umbraco.NodeFactory.Node(relation.ChildId); 
     } 
     else 
     { 
      node = new umbraco.NodeFactory.Node(relation.ParentId); 
     } 

     <text>@node.NiceUrl</text>   <br /> 
    } 

} } 

我還試圖用剃刀與拉姆達[其中]語句來查詢結果僅供別名,但它並沒有在視圖中工作。我可能會將此移到控制器,但它在視圖中起作用。