In our DD4T project, we have a need to pass certain contextual information from the Page view to the Component Presentation view - specifically, there are classes nested within the Component Presentation view that must differ according to the Page Template on which the CT is used (in such a way that these containers can't be moved to the PT view). Unfortunately, changing the markup is not an option as this is the product of a fairly complex responsive grid system.
The way we're handling this at the minute works but is fairly ugly - grabbing the Page Template from the IComponentPresentation
and switching out the CSS class accordingly within the CP view. As you can imagine, this is shaping up to be a maintenance nightmare as the need to reuse CTs on various Page Templates emerges.
What we need is essentially the routeValues
parameter of ChildActionExtensions.Action
, so I could do something like this:
@Html.RenderComponentPresentations(new { SomeParameter = "SomeValue" })
Then I could just pass my class into the CP, for example. However, I can't see anywhere to pass additional routevalues in via the current RenderComponentPresentations
helper, nor anything on the IComponentPresentationRenderer
interface that would let me write my own helper and/or custom renderer.
So, I'm a bit stuck. Short of doing something funky like adding the classes into the ViewBag in the Page view and then pulling them off the HtmlHelper in a custom CP renderer - or reimplementing a load of framework logic to call the CP actions directly - I can't see an elegant solution.
Has anyone managed to solve this issue before? It seems as though IComponentPresentationRender.RenderComponentPresentation
could use an overload that accepts a parameter for additional route values.