4

In DXA, we can create listing pages to list items based on schema [Article] and [News Article].
Now I haved creates a schema named [Special Offer] and corresponding view and model in a custom module [TrainingEducation]. It worked well.
The next step, I want to create a listing page to list items based on my new schema.
I found that in DXA Core Module, the model used for Listing is [ContentList.cs], controller used for Listing is [ListController.cs] and view used for listing is [PagedList.cshtml]. I'm trying to create a new view used for listing my custom items and use it with the model & controller used in Core.
Below is the figure for my idea:
enter image description here I added the code at the top of the new view used for listing.

@model Sdl.Web.Modules.Core.Models.ContentList<SpecialOffer>

I registered the new view using below code.

RegisterViewModel("List", typeof(ContentList<SpecialOffer>), "List");

In CME:
1. I created a new keyword in [Content Type]   enter image description here 2. I created a new CT linked with the new view: enter image description here
3. I created a listing page using component based on schema [Content Query] and new CT. The page showed like below: enter image description here

The Content Query Component used for listing:
enter image description here
enter image description here
The items showed on the listing page have no idea with components based on schema [Special Offer]. I don't know where the component are from. And have no idea about which step should I take.
Any information or advice would be appreciated.
Thanks in advance.

  • How does your List Component (Content Query) look in CM? – Rick Pannekoek Feb 16 '17 at 18:24
  • Hi Rick. I added the captures of the list component. – Heimei Feb 17 '17 at 0:41
2

Functionally speaking, if you say the list contains unexpected items, it sounds like you didn't properly specify the query for the list in CM.

Technically speaking, the flow is as follows:

  • You create a Component representing the dynamic list and the query to execute (currently not shown in your Question)
  • You put it on a Page together with a CT which references the ListController.List action (as shown)
  • Before the Entity Model representing the list/query gets rendered, the ListController.List method is executed and that calls IContentProvider.PopulateDynamicList in order to execute the query and get the Entity Model populated with the results.
  • DefaultContentProvider.PopulateDynamicList obtains the Query from the Entity Model and lets class BrokerQuery execute the broker query and map the results to Entity Models.
  • BrokerQuery.ExecuteQuery runs the broker query, obtains IComponentMeta for each resulting Component ID, creates a lightweight DD4T Component object from it and then uses ModelBuilderPipeline.CreateEntityModel to create an Entity Model using regular semantic mapping.

Note that the semantic mapping of the query results is done based on Component Meta only, meaning that only some system metadata (Title, Published Date) and custom metadata is available. See, for details: https://github.com/sdl/dxa-web-application-dotnet/blob/release/1.6/Sdl.Web.Tridion/Query/BrokerQuery.cs

  • It seems that we can only use the metadata(title, created date) of resulting components. I set a metadata field in my schema and try to render this metadata field in my listing view, but in result, the page turned out blank. – Heimei Feb 17 '17 at 5:35
1

Three causes of this problem:
1. The field [Key] of keyword should be trainingeducation.specialOffer
2. Only custom metadata is available
I was trying to render fields in my list view which are not available
3. In my listing model, foe example I used [SemanticProperty("s:dateCreated")], the content was not shown, but if I delete [s:] ([SemanticProperty("dateCreated")]), the content of [dateCreated] appeared on listing page.

I'm not clear about the reason of the third point, but it did solve the problem.

  • 1
    I guess you declared the s prefix to refer to the schema.org vocabulary. That is typically done to expose property semantics in the HTML. However, such semantics cannot be used for CM model mapping, unless you would add semantic annotations to the CM Schema field. Without such annotations, CM Schema fields are implicitly in the DXA Core Vocabulary and so are View Model properties. – Rick Pannekoek Feb 17 '17 at 9:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.