2017-03-08 21 views
0

嗨,大家好我是新來的,在Umbraco cms。我創建了一個文檔類型,它有一個屬性(media picker)。 我的問題是我怎樣才能撥打media picker進入不同的頁面。 讓我說我會創建另一個頁面,並會調用我從其他頁面創建的屬性。 希望有人能幫助我。 我已經通過他們的網站和谷歌搜索,但我沒有運氣找到更好的解決方案。如何在umbraco中獲取房產價值7

@if (CurrentPage.HasValue("teaserImage")) 
{ 
    var caseStudyImagesList = CurrentPage.CaseStudyImages.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); 
    var caseStudyImagesCollection = Umbraco.Media(caseStudyImagesList); 

    foreach (var caseStudyImage in caseStudyImagesCollection) 
    { 
     <img src="@caseStudyImage.Url" /> 
    } 
} 
+0

因此,在頁面上有一個屬性「teaserImage」,你想從頁面B訪問它? – Eyescream

+0

是的,這是正確的.. – daidara

回答

1

您可以通過多種方式從頁面B獲取頁面A的節點。 例如:

// you can get the A node with its ID if you have it 
int idPageA = 1207; 
IPublishedContent nodeA = Umbraco.TypedContent(idPageA); 
// or maybe by moving through the tree, Model.Content is the typed version of currentpage, so you have intellisense 
IPublishedContent nodeA = Model.Content.Parent.Children().Where(x => x.GetPropertyValue<string>("propertyAlias") == "nodeA"); 
IPublishedContent nodeA = Model.Content.Parent.Children().Where(x => x.Name == "Node A Name"); 

if (nodeA.HasValue("teaserImage")) 
{ 
    var caseStudyImagesList = nodeA.GetPropertyValue<string>(CaseStudyImages).Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); 
    var caseStudyImagesCollection = Umbraco.TypedMedia(caseStudyImagesList); 

    foreach (var caseStudyImage in caseStudyImagesCollection) 
    { 
     if(caseStudyImage != null){ 
      <img src="@caseStudyImage.Url" /> 
     } 
    } 
}