我正在使用 Orchard CMS v1.8.x。我们添加了 FlexSlider 模块并使其链接到我们网站的特定区域,我们在 FlexSliderPart 对象中添加了一个名为“Slide Link”的字段。
现在,这一切都很好。但我完全不知道如何在前端引用这个新字段。FlexSliderWidgetViewModel 仅包含 Title 和 ImagePath 字段。我不知道如何检索 SlideLink(和 SubTitle)字段:
namespace Tekno.FlexSlider.ViewModels
{
public class FlexSliderWidgetViewModel
{
public string Title { get; set; }
public string ImagePath { get; set; }
}
}
我的观点:
@using Tekno.FlexSlider.ViewModels
@{
Style.Require("FlexSlider");
Script.Require("FlexSlider");
var items = (IEnumerable<FlexSliderWidgetViewModel>)Model.SlideItems;
}
<div class="flexslider">
<ul class="slides">
@foreach (var item in items)
{
<li>
@if (item.ImagePath != "")
{
<a href="@(/*what must I do here?*/)"><img src="@Display.ResizeMediaUrl(Path: item.ImagePath, Height: 400, Mode: "crop")" /></a>
}
<span class="slide-text">@item.Title</span>
</li>
}
</ul>
<span class="slide-text-bottom"></span>
</div>
驾驶员显示功能:
protected override DriverResult Display(FlexSliderWidgetPart part, string displayType, dynamic shapeHelper)
{
var items = _contentManager.Query<FlexSliderPart, FlexSliderPartRecord>("FlexSlider")
.Where(i => i.GroupId == part.GroupId).OrderBy(i => i.Sort)
.List()
.Select(i => new FlexSliderWidgetViewModel()
{
ImagePath = ((MediaLibraryPickerField)i.Fields.Single(f => f.Name == "Picture"))
.MediaParts
.FirstOrDefault() == null ? "" : ((MediaLibraryPickerField)i.Fields.Single(f => f.Name == "Picture")).MediaParts.First().MediaUrl,
Title = i.Get<TitlePart>().Title
});
return ContentShape("Parts_FlexSliderWidget",
() => shapeHelper.Parts_FlexSliderWidget(SlideItems: items));
}