November Happy Hour will be moved to Thursday December 5th.

Conditional display templates for page blocks

Vote:
 

Hi,

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!

#90191
Sep 03, 2014 13:20
Vote:
 

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

http://tech-fellow.net/2014/02/11/bootstrap-aware-episerver-content-area-render/

#90193
Sep 03, 2014 13:26
Vote:
 

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

Frederik

#90195
Sep 03, 2014 13:35
Vote:
 

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 :)

#90197
Sep 03, 2014 13:41
Vote:
 

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 :)

#90202
Sep 03, 2014 15:06
Vote:
 

Thank you guys! Works like a charm :)

#90235
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.