如何将内容选择器上的选定节点显示到首页
How to show selected node on content picker to front page
我想创建一个 selection of banner with Content Picker' 到 select 节点以使用其他横幅。 http://screencast.com/t/3gb6TeAe
现在我想知道如何在内容选择器上显示 selected 横幅并将其显示在首页。任何简单的方法。
我已经尝试获取 selected 节点的 Url。
var nodeId = Model.Content.GetPropertyValue("selectBanner");
var node = Umbraco.TypedContent(nodeId);
<a href="@node.Url">@node.Name</a>
据我所知,您的横幅文档类型中有一个媒体选择器。所以您需要访问横幅图片 Url...您可以执行以下操作
var node = Model.Content; // Your content of type banner
var imgUrl = Umbraco.Media(node.GetPropertyValue("selectBanner")).Url // getting property for image and then its url
<a href="@imgUrl">@node.Name</a>
或者如果您只想显示图像
<img src="@imgUrl"/>
如果我的理解是正确的,您首先需要获取横幅节点:
// This gets the node selected by your content picker
var bannerNode = Umbraco.TypedContent(Model.Content.GetPropertyValue<int>("selectBanner"));
然后您需要获取横幅节点上指定的图像:
// This gets you the image/media set on the banner nodes media picker property
var img = Umbraco.Media(bannerNode.GetPropertyValue("mediaPickerPropertyAlias")).Url
然后您可以访问 bannerNode url:
@bannerNode.Url
或横幅节点上指定的图像:
@img.Url
我想创建一个 selection of banner with Content Picker' 到 select 节点以使用其他横幅。 http://screencast.com/t/3gb6TeAe
现在我想知道如何在内容选择器上显示 selected 横幅并将其显示在首页。任何简单的方法。
我已经尝试获取 selected 节点的 Url。
var nodeId = Model.Content.GetPropertyValue("selectBanner");
var node = Umbraco.TypedContent(nodeId);
<a href="@node.Url">@node.Name</a>
据我所知,您的横幅文档类型中有一个媒体选择器。所以您需要访问横幅图片 Url...您可以执行以下操作
var node = Model.Content; // Your content of type banner
var imgUrl = Umbraco.Media(node.GetPropertyValue("selectBanner")).Url // getting property for image and then its url
<a href="@imgUrl">@node.Name</a>
或者如果您只想显示图像
<img src="@imgUrl"/>
如果我的理解是正确的,您首先需要获取横幅节点:
// This gets the node selected by your content picker
var bannerNode = Umbraco.TypedContent(Model.Content.GetPropertyValue<int>("selectBanner"));
然后您需要获取横幅节点上指定的图像:
// This gets you the image/media set on the banner nodes media picker property
var img = Umbraco.Media(bannerNode.GetPropertyValue("mediaPickerPropertyAlias")).Url
然后您可以访问 bannerNode url:
@bannerNode.Url
或横幅节点上指定的图像:
@img.Url