Try our conversational search powered by Generative AI!

Render Pages and Blocks in same ContentArea


I am playing around with idea of allowing pages and blocks in a content area for a list, and want to render them similarly. I have 2 block types that share similar properties that will be allowed in the area, and would like to allow Pages to be added in as well. Using a ViewModel, I am populating the same set of properties from each block, and would be populating the ViewModel using the Page as well. 

How do I properly handle this scenario? I was going down the route of a PartialContentController and specifying a Tag on the PropertyFor in the view, but it's not hit for both scenarios, and I'm not wrapping my head around it clear enough right now to tinker in the right direction. Is there a way to use a Partial Controller, or some other Controller, and check the content type before handling the data however, and rendering the Partial?


Aug 26, 2016 5:41

You can sett allowed types on the content area in the model as well. That will make it not possible to drop "wrong" contenttypes into the area. You can also use a class that inheritsIViewTemplateModelRegistrator instead of controllers.

Have a look in the demo package from episerver, alloy templates mvc. They use this. You can read more at,

Aug 26, 2016 9:05

This isn't about setting allowed types. I wasn't clear on that, and I apologize. This is about handling the PageData in the ContentArea and the BlockData. For an example, consider a navigation section where it could be an internal page link, or an outside, custom link. For the internal page link, I want to allow a page to be dropped in, and for outside, there are a couple options defined as Blocks that inherit INnavItem. 

My AllowedTypes and property would be defined like:

public virtual ContentArea ThisNavigation {get;set;}

Now, when I do

@Html.PropertyFor(m=> m.ThisNavigation);

It will render the blocks according to their controller or matching view. For the page, you can specify a PartialContentController. Or am I wrong here? If I am right, how do I make that PartialContentController only apply to items in this list? For instance, PageData in this list I want to render differently than it would dragged into any other ContentArea. I might have a "Callout" ContentArea somewhere that allows only PageData and in that list the Page will render with an Image and Teaser wrappedin a Link to the page like a typical callout. 

Hopefully that helps clarify the state my mind is at right now with playing with these ideas. I'm sure I'm missing a concept or approach.

At any rate, thanks for replying and helping.

Aug 26, 2016 17:42

I wrote a blog post a few years ago where I do something similar. It might be just what you need:

Aug 26, 2016 18:33

As Per Magne Skuseth does in his blog post, adding a Tag is the way to go for this.

You keep your default page controller as is and setup your new one to a specific tag that you supply when you render with PropertyFor.

For the rendering with the tag the pagedata will be routed to your new controller and everywhere else it will be routed to your default controller.

Aug 29, 2016 10:11

Thanks Per and Erik for pointing that out. I was missing the tag on the partial controller. I basically created the same solution before running into the issue and searching, so I wish I would have posted sooner. It would have saved me a bit of time. But, on the flip side, it lets me know I am not far off base with my line of thinking if Per has done this in the past and it was a good idea then. :) Makes me feel a little better.

Adding the tag to the template descriptor made everything click into place and work as I need it. The blocks I already had rendering as needed so this zipped up the solution nicely.

Again, thanks for both of you pointing out that missing piece, and supplying the blog link to the solution.

Aug 29, 2016 15:45
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.