Replies: 5 comments
-
@hylinux you are missing BuildDispay in your foreach @foreach ( ContentItem contentItem in Model.ContentItems )
{
@await Orchard.DisplayAsync(await DisplayManager.BuildDisplayAsync(contentItem , null, "Detail"))
} This will render |
Beta Was this translation helpful? Give feedback.
-
@ns8482e thanks for your sharing. I saw the document: https://docs.orchardcore.net/en/latest/docs/reference/core/Razor/, it saying:
·Renders a content item with the corresponding display type.· I suppose it just need a paramter named 'ContentItem' which is mean I used the Razor Help function. not the OrchareCore function... any idea what's the correct template file name for Razor Help fucntion `DisplayAsync'? thanks agian. |
Beta Was this translation helpful? Give feedback.
-
also, look like this code it doesn't work too. :(\ @using OrchardCore.DisplayManagement;
@inject IDisplayManager<ContentItem> _displayManager
@foreach ( ContentItem contentItem in Model.ContentItems )
{
@await DisplayAsync(await _displayManager.BuildDisplayAsync(contentItem, null))
<b>Test1</b><br/>
} |
Beta Was this translation helpful? Give feedback.
-
and I checked the source code for Razor helper. public static class OrchardRazorHelperExtensions
{
public static async Task<IHtmlContent> DisplayAsync(this IOrchardDisplayHelper orchardDisplayHelper, ContentItem content, string displayType = "", string groupId = "", IUpdateModel updater = null)
{
var displayManager = orchardDisplayHelper.HttpContext.RequestServices.GetService<IContentItemDisplayManager>();
var shape = await displayManager.BuildDisplayAsync(content, updater, displayType, groupId);
return await orchardDisplayHelper.DisplayHelper.ShapeExecuteAsync(shape);
} it look like a correct syntax, but I don't know why it doesn't works. |
Beta Was this translation helpful? Give feedback.
-
ok, I got it. I have to use detail DisplayType for it: @foreach ( ContentItem contentItem in Model.ContentItems )
{
@await Orchard.DisplayAsync(contentItem, "Detail")
} it will take the template file "Content-Article.Detail.cshtml" if I didn't put the DisplayMode, it will not point to "Content-Article.cshtml", which is werid. I guess it should be this code problem: var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(contentItem.ContentType);
if (contentTypeDefinition == null)
{
throw new NullReferenceException($"Content Type {contentItem.ContentType} does not exist.");
}
var actualDisplayType = String.IsNullOrEmpty(displayType) ? "Detail" : displayType;
var hasStereotype = contentTypeDefinition.TryGetStereotype(out var stereotype);
var actualShapeType = "Content";
if (hasStereotype)
{
actualShapeType = contentTypeDefinition.GetStereotype();
}
// [DisplayType] is only added for the ones different than Detail
if (actualDisplayType != "Detail")
{
actualShapeType = actualShapeType + "_" + actualDisplayType;
} in if |
Beta Was this translation helpful? Give feedback.
-
Hi, Everyone.
I got very confuse about this part:
I have create few Content Types:
ArticlePage
Content Type which have aListPart
. and the ListPart contain another ContentType:Article
.when I tried to render ArticlePage, I got Template:
Content-AritclePage.cshtml
. in this template, I will render ListPart by this code:this code works well, it will render template file:
ArticlePage-ListPart.cshtml
.when I tried to render detail list in ListPart, I wrote code in
ArticlePage-ListPart.cshtml
:Per design, here's the
contentItem
should beArticle
Content Type. I created a copule themes files, include:ArticlePage-ListPart-Aritcle.cshtml
Content-Article.cshtml
ListPart-Article.cshtml
but non of them was render.
would you share with me what's I did wrong? what's the correct theme file name?
thanks
Beta Was this translation helpful? Give feedback.
All reactions