Is there a way to manually set the content items on a ContentView templated server control?

StackOverflow https://stackoverflow.com/questions/19694292

  •  02-07-2022
  •  | 
  •  

Question

The examples I'm seeing for the new ContentView templated server control all use a ContentModelSource server control on the front end. What if I have a method already created that uses the FrameworkAPI and sets all sorts of weird filters in the criteria object and returns a List<ContentData>. Is there a way I can pass that list of content data into my ContentView server control and totally skip having any sort of ContentModelSource control on the page?

Was it helpful?

Solution 2

I've done a lot of digging into this issue, and I've discovered the following things:

  • It is true that a ContentModelSource is required to use the ContentView server control. You get an ugly .NET exception if you try to go without it.
  • You are not required to actually get the data from that ContentModelSource
  • Data can be set by using the SelectMethod property on the ContentView control. Set it to the name of a public method on your page that returns either ContentData or List<ContentData>.
  • Alternatively, you can wait until the Page_Load event and set the Model.ContentList property. You get a .NET exception (Null Reference, i think) if you try to set it during Page_Init.

ASPX:

<ektron:ContentModelSource runat="server" ID="cmsNull"></ektron:ContentModelSource>

<ektron:ContentView runat="server" ID="cvPrimary" ModelSourceID="cmsNull">
</ektron:ContentView>

C#:

protected void Page_Load(object sender, EventArgs e)
{
    var cm = new ContentManager();

    var criteria = new ContentCriteria();
    criteria.AddFilter(ContentProperty.Type, CriteriaFilterOperator.EqualTo, EkEnumeration.CMSContentType.Content);

    cvPrimary.Model.ContentList = cm.GetList(criteria);
}

OTHER TIPS

You must use the ContentModelSource when using the ContentView.

However, you could use your existing Framework API commands to get the content you want and then pass the content IDs to the ContentModelSource control in C# code:

    ContentModelSource1.ContentFilters.Add(new Ektron.Cms.Framework.UI.Controls.ContentFilter()
            {
                Value = myContentIds, 
                Operator = Ektron.Cms.Common.CriteriaFilterOperator.In, 
                Field = Ektron.Cms.Common.ContentProperty.Id
            });

This will fill your ContentModelSource with all of your content IDs.

Alternatively you can use regular .Net controls like a Repeater to write out your content item results.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top