大家好,我也是 Umbraco cms 的新人。我创建了一个文档类型,它有一个属性(media picker)
。
我的问题是如何将media picker
调用到不同的页面。
假设我将创建另一个页面,并将调用我从其他页面创建的属性。
希望可以有人帮帮我。
我搜索他们的网站和谷歌,但我没有运气找到更好的解决方案。
@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 :(得分:2)
您可以通过多种方式从页面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" />
}
}
}