Orchard CMS 部件放置
Orchard CMS Part placement
我一直在努力将内容项的特定部分放置在视图中。我的问题是如何为内容项定义 cshtml
view/shape 以便我可以将每个部分放在我想要的位置。考虑以下内容项:
item
- Text field
- Media field
以及以下
<div class="my text">
@Model.TextField1
<div class="media-item">
@Model.MediaField
</div>
</div>
<p> Some text or stuf here or anyehere</p>
我似乎找不到任何这样的例子。它应该是一个内容的基本视图,该内容的每个部分都有分配的对象,但我发现它不可能实现(顺便说一句,我不想使用布局)。
你的问题没有包含很多细节来真正确定你的问题是什么,但这里有一些建议:
确保您的 Placement.info 文件对于您尝试使用的 DisplayType 是最新的,这是我的一个示例:
<Placement>
<Place Parts_McrfProfile_Edit="Content:3"/>
<Place Parts_McrfProfile_Summary="Content:6"/>
<Place Parts_McrfProfileList_Edit="Content:3"/>
<Place Parts_McrfProfileList_Summary="Content:6"/>
<Place Parts_McfProfile_List="Content:6"/>
<Match DisplayType="Detail">
<!-- hide summary, show full content, for Detail -->
<Place Parts_McrfProfile_Summary="-"
Parts_McrfProfileList_Summary="-"
Parts_McfProfile_List="-"
Parts_McrfProfile="Content:6"
Parts_McrfProfileList="Content:6"
/>
<Place Parts_Common_Metadata="-"/>
</Match>
<Match DisplayType="Summary">
<Place Parts_Common_Metadata_Summary="-"/>
</Match>
<Match DisplayType="ListView">
<Place Parts_Common_Metadata_Summary="-"
Parts_McrfProfile_Summary="-"
Parts_McrfProfileList_Summary="-"
Parts_McrfProfile="-"
Parts_McrfProfileList="-"
Parts_McrfProfile_List="Content:6"/>
</Match>
</Placement>
然后在你的显示驱动程序中,确保你正在构建正确的显示类型,这里是一个使用几个的例子:
protected override DriverResult Display(
McrfProfilePart part, string displayType, dynamic shapeHelper)
{
return Combined(
ContentShape("Parts_McrfProfile",
() =>
{
part.ProfileDetail = _profileService.GetProfileDetail(part.ProfileId);
McrfProfileDetailViewModel profileDetailViewModel = new McrfProfileDetailViewModel();
profileDetailViewModel.ProfileDetail = part.ProfileDetail;
return shapeHelper.Parts_McrfProfile(ProfileDetail: profileDetailViewModel);
}),
ContentShape("Parts_McrfProfile_List",
() =>
{
return shapeHelper.Parts_McrfProfile_List(ProfileRecord: part);
}),
ContentShape("Parts_McrfProfile_Summary",
() =>
{
McrfProfileSummaryViewModel profileSummaryViewModel = new McrfProfileSummaryViewModel();
List<int> profileID = new List<int>() { part.ProfileId };
var summary = _profileService.GetProfileSummaryList(profileID).Where(e => e.ProfileID == part.ProfileId).First();
profileSummaryViewModel.JobTitle = summary.JobTitle;
profileSummaryViewModel.Name = summary.Name;
profileSummaryViewModel.ProfileImage = summary.ProfileImage;
profileSummaryViewModel.ProfileID = summary.ProfileID;
return shapeHelper.Parts_McrfProfile_Summary(ProfileRecord: profileSummaryViewModel);
}));
}
最后,如果您已正确完成这些操作并从您的服务中获取有效数据(或通过任何方式获取数据),您应该能够按如下方式使用您的视图:
@{
Mcrf.Profiles.ViewModels.McrfProfileDetailViewModel part = Model.ProfileDetail;
Style.Include("profile-styles.css?v=1.0").AtHead();
Style.Include("bootstrap.css?v=1.0").AtHead();
}
@if (Model != null && part.ProfileDetail != null)
{
<div>
<div >
<div class="profileImgDiv">
@if (Model != null && part != null)
{
if (part.ProfileDetail.ProfileImage == null)
{
<img class="profile-img" src="~/Modules/Mcrf.Profiles/Content/Images/noProfilePictureImage.jpg" />
}
else
{
<img class="profile-img" src="@Url.Content(part.ProfileDetail.ProfileImage)" />
}
}
</div>
等等,等等,等等,
希望对您有所帮助,
罗卡
如果您有工作替代方案,例如 Content-MyContentType.cshtml,您可以执行以下操作:
<div class="my text">
@Display(Model.TextFields)
<div class="media-item">
@Display(Model.Media)
</div>
</div>
<p> Some text or stuf here or anyehere</p>
然后你可以在 placement.info:
<Match ContentType="MyContentType">
<Place Fields_Common_Text="TextFields" />
<Place Fields_MediaLibraryPicker="Media" />
</Match>
备注
我不确定您的文本字段 and/or 您的媒体是什么类型的字段,因此您可能需要更改 Fields_Common_Text 和 Fields_MediaLibraryPicker 以匹配您的字段类型。
我一直在努力将内容项的特定部分放置在视图中。我的问题是如何为内容项定义 cshtml
view/shape 以便我可以将每个部分放在我想要的位置。考虑以下内容项:
item
- Text field
- Media field
以及以下
<div class="my text">
@Model.TextField1
<div class="media-item">
@Model.MediaField
</div>
</div>
<p> Some text or stuf here or anyehere</p>
我似乎找不到任何这样的例子。它应该是一个内容的基本视图,该内容的每个部分都有分配的对象,但我发现它不可能实现(顺便说一句,我不想使用布局)。
你的问题没有包含很多细节来真正确定你的问题是什么,但这里有一些建议:
确保您的 Placement.info 文件对于您尝试使用的 DisplayType 是最新的,这是我的一个示例:
<Placement>
<Place Parts_McrfProfile_Edit="Content:3"/>
<Place Parts_McrfProfile_Summary="Content:6"/>
<Place Parts_McrfProfileList_Edit="Content:3"/>
<Place Parts_McrfProfileList_Summary="Content:6"/>
<Place Parts_McfProfile_List="Content:6"/>
<Match DisplayType="Detail">
<!-- hide summary, show full content, for Detail -->
<Place Parts_McrfProfile_Summary="-"
Parts_McrfProfileList_Summary="-"
Parts_McfProfile_List="-"
Parts_McrfProfile="Content:6"
Parts_McrfProfileList="Content:6"
/>
<Place Parts_Common_Metadata="-"/>
</Match>
<Match DisplayType="Summary">
<Place Parts_Common_Metadata_Summary="-"/>
</Match>
<Match DisplayType="ListView">
<Place Parts_Common_Metadata_Summary="-"
Parts_McrfProfile_Summary="-"
Parts_McrfProfileList_Summary="-"
Parts_McrfProfile="-"
Parts_McrfProfileList="-"
Parts_McrfProfile_List="Content:6"/>
</Match>
</Placement>
然后在你的显示驱动程序中,确保你正在构建正确的显示类型,这里是一个使用几个的例子:
protected override DriverResult Display(
McrfProfilePart part, string displayType, dynamic shapeHelper)
{
return Combined(
ContentShape("Parts_McrfProfile",
() =>
{
part.ProfileDetail = _profileService.GetProfileDetail(part.ProfileId);
McrfProfileDetailViewModel profileDetailViewModel = new McrfProfileDetailViewModel();
profileDetailViewModel.ProfileDetail = part.ProfileDetail;
return shapeHelper.Parts_McrfProfile(ProfileDetail: profileDetailViewModel);
}),
ContentShape("Parts_McrfProfile_List",
() =>
{
return shapeHelper.Parts_McrfProfile_List(ProfileRecord: part);
}),
ContentShape("Parts_McrfProfile_Summary",
() =>
{
McrfProfileSummaryViewModel profileSummaryViewModel = new McrfProfileSummaryViewModel();
List<int> profileID = new List<int>() { part.ProfileId };
var summary = _profileService.GetProfileSummaryList(profileID).Where(e => e.ProfileID == part.ProfileId).First();
profileSummaryViewModel.JobTitle = summary.JobTitle;
profileSummaryViewModel.Name = summary.Name;
profileSummaryViewModel.ProfileImage = summary.ProfileImage;
profileSummaryViewModel.ProfileID = summary.ProfileID;
return shapeHelper.Parts_McrfProfile_Summary(ProfileRecord: profileSummaryViewModel);
}));
}
最后,如果您已正确完成这些操作并从您的服务中获取有效数据(或通过任何方式获取数据),您应该能够按如下方式使用您的视图:
@{
Mcrf.Profiles.ViewModels.McrfProfileDetailViewModel part = Model.ProfileDetail;
Style.Include("profile-styles.css?v=1.0").AtHead();
Style.Include("bootstrap.css?v=1.0").AtHead();
}
@if (Model != null && part.ProfileDetail != null)
{
<div>
<div >
<div class="profileImgDiv">
@if (Model != null && part != null)
{
if (part.ProfileDetail.ProfileImage == null)
{
<img class="profile-img" src="~/Modules/Mcrf.Profiles/Content/Images/noProfilePictureImage.jpg" />
}
else
{
<img class="profile-img" src="@Url.Content(part.ProfileDetail.ProfileImage)" />
}
}
</div>
等等,等等,等等,
希望对您有所帮助,
罗卡
如果您有工作替代方案,例如 Content-MyContentType.cshtml,您可以执行以下操作:
<div class="my text">
@Display(Model.TextFields)
<div class="media-item">
@Display(Model.Media)
</div>
</div>
<p> Some text or stuf here or anyehere</p>
然后你可以在 placement.info:
<Match ContentType="MyContentType">
<Place Fields_Common_Text="TextFields" />
<Place Fields_MediaLibraryPicker="Media" />
</Match>
备注
我不确定您的文本字段 and/or 您的媒体是什么类型的字段,因此您可能需要更改 Fields_Common_Text 和 Fields_MediaLibraryPicker 以匹配您的字段类型。