Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content shape alternate targeting a specific item with ContentItemId (#15572) #16679

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/OrchardCore.Modules/OrchardCore.Contents/Shapes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,18 @@ public override ValueTask DiscoverAsync(ShapeTableBuilder builder)
// Content__[ContentType] e.g. Content-BlogPost,
displaying.Shape.Metadata.Alternates.Add("Content__" + encodedContentType);

// Content__[ContentItemId] e.g. Content-42n8364bk2azcy1yd71gnrntwf,
displaying.Shape.Metadata.Alternates.Add("Content__" + contentItem.ContentItemId.EncodeAlternateElement());

// Content__[Id] e.g. Content-42,
displaying.Shape.Metadata.Alternates.Add("Content__" + contentItem.Id);

// Content_[DisplayType]__[ContentType] e.g. Content-BlogPost.Summary
displaying.Shape.Metadata.Alternates.Add("Content_" + displaying.Shape.Metadata.DisplayType + "__" + encodedContentType);

// Content_[DisplayType]__[ContentItemId] e.g. Content-42n8364bk2azcy1yd71gnrntwf.Summary
displaying.Shape.Metadata.Alternates.Add("Content_" + displaying.Shape.Metadata.DisplayType + "__" + contentItem.ContentItemId.EncodeAlternateElement());

// Content_[DisplayType]__[Id] e.g. Content-42.Summary
displaying.Shape.Metadata.Alternates.Add("Content_" + displaying.Shape.Metadata.DisplayType + "__" + contentItem.Id);
}
Expand Down
44 changes: 44 additions & 0 deletions src/docs/reference/modules/Templates/README.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,50 @@ For instance, when a content item is displayed in a list, the `Summary` display
| `Content_Summary__BlogPost` | `Content-BlogPost.Summary.cshtml` |
| `Content_Summary__Article` | `Content-Article.Summary.cshtml` |

### `Content__[ContentItemId]`

This template is called when displaying a content item with a specific ContentItemId.

#### Content with specific ContentItemId Examples

| Template | Filename|
| --------- | ------------ |
| `Content__42n8364bk2azcy1yd71gnrntwf` | `Content-42n8364bk2azcy1yd71gnrntwf.cshtml`

### `Content_[DisplayType]__[ContentItemId]`

This template is called when displaying a content item with a specific display type and ContentItemId.
For instance, when a content item is displayed in a list, the `Summary` display type is commonly used.

#### Content with specific Display Type and ContentItemId Examples

| Template | Filename|
| --------- | ------------ |
| `Content_Summary__42n8364bk2azcy1yd71gnrntwf` | `Content-42n8364bk2azcy1yd71gnrntwf.Summary.cshtml`

### `Content__[Id]`

This template is called when displaying a content item with a specific Id.

Note: This template was supported on Orchard version 1.X and will probably be removed from future versions. It is strongly recommended to use the corresponding template that utilizes the ContentItemId.
dmourtzoukos marked this conversation as resolved.
Show resolved Hide resolved

#### Content with specific Id Examples

| Template | Filename|
| --------- | ------------ |
| `Content__12` | `Content-12.cshtml`

### `Content_[DisplayType]__[Id]`

This template is called when displaying a content item with a specific display type and Id.
For instance, when a content item is displayed in a list, the `Summary` display type is commonly used.

#### Content with specific Display Type and Id Examples

| Template | Filename|
| --------- | ------------ |
| `Content_Summary__12` | `Content-12.Summary.cshtml`

### `Content__Alias__[Alias]`

This template is called when displaying a content item with a specific alias. It needs to have the `AliasPart` attached to it.
Expand Down