Conditional display templates for page blocks



I have an EmployeeBlock which can drag & dropped to ContentAreas on StartPage, AboutUs page, etc.
Can I control the rendering of that block based on current page?

When I'm on the start page and call Html.PropertyFor(x => x.MyContentArea), I want to use one view / display template, and when I call the same helper on AboutUs page, I want to use other view / display template.
Can I somehow submit additional html attributes to PropertyFor helper and then use different views based on that value? Something like this:

@Html.PropertyFor(x => x.MyContentArea, new { view = "StartPage" })
@Html.PropertyFor(x => x.MyContentArea, new { view = "AboutUsPage" })

Any helper would be greatly appreciated!

Sep 03, 2014 13:20

Hm, this sounds a great extension for ContentArea render :)

Sep 03, 2014 13:26

I would just use Tags for selecting the right template/view. All built in.


Sep 03, 2014 13:35

Hi Valdis,

I have a content area which contains blocks which contain content areas which contain blocks ... :)
So the "lowest level" block needs to take a display option from the top level content area, and I don't want to control this from the edit mode :)

To make the things more clear:
Let's say that I want to display a list of employees on the start page and about us page.
There's no separate page for each employee, and I want to reuse the content so I decided to create shared blocks.
On start page, I want to display the following info for each employee: photo, name, etc.
On About Us page, I want to display: photo, name, title, fancy background image, etc.

I don't want to let the editor to control the rendering because that's written in stone by our GUI / UX guys :)

Sep 03, 2014 13:41

Dejan, if that's requirements recommend to take a closer look at Alloy templates and tags. As Fredrik said, that should just solve your stuff. I though you have more complex requirements :)

Sep 03, 2014 15:06

Thank you guys! Works like a charm :)

Sep 04, 2014 10:47
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.