Not sure exactly how your setup is, but is it possible to add arguments as RenderSettings?
Forgot to mention that this is MVC. Isn't RenderSettings a WebForms specific thing?
I've tried to pass on arguments with
@Html.PropertyFor(x => x.Area, new { CustomSomething = "test" })
the retrive it with
@ViewData["CustomSomething"]
without any luck. I guess this is only available in the ContentArea display template.
I have done exactly that to pass down data from Containing ContentArea rendering to blocks
@Html.PropertyFor(model => model.MyContentArea, new { CustomSomething = "something" })
var something = blockController.ControllerContext.ParentActionViewContext.ViewData["CustomSomething"] != null ? blockController.ControllerContext.ParentActionViewContext.ViewData["CustomSomething"] : null;
Not to confuse the matter but I actually use it as a short cut to providing different rendering for the block types.
Rather than implementing new controllers which render when a specific tag is set, I pass a RenderTag down to the blocks using this method.
@Html.PropertyFor(model => model.MyContentArea, new { RenderTag= "specificRenderTag" })
Then in my block controllers I implement as follows:
public override ActionResult Index(MyBlock currentBlock)
{
string viewName = this.TryGetRenderTagView();
return this.PartialView(viewName, currentBlock);
}
TryGetRenderTagView() will return the default "Index" OR if the RenderTag is found in the ParentActionViewContext AND it can find a view with same name as the RenderTag, then it will return the RenderTag.
public static string TryGetRenderTagView<T>(this EPiServer.Web.Mvc.BlockController<T> blockController) where T : BlockData
{
string retval = "Index";
var parentRenderTag = blockController.TryGetParentRenderTag();
if (!string.IsNullOrWhiteSpace(parentRenderTag))
{
var viewResult = new PartialViewResult().ViewEngineCollection.FindPartialView(blockController.ControllerContext, parentRenderTag);
if (viewResult != null && viewResult.View != null)
{
retval = parentRenderTag;
}
}
return retval;
}
public static string TryGetParentRenderTag<T>(this EPiServer.Web.Mvc.BlockController<T> blockController) where T : BlockData
{
return blockController.ControllerContext.ParentActionViewContext.ViewData[MagicStrings.ViewDataKeys.RenderTag] != null ? blockController.ControllerContext.ParentActionViewContext.ViewData[MagicStrings.ViewDataKeys.RenderTag].ToString() : null;
}
I have a block containing a content area. I wish to pass on arguments to the blocks inside this content area from the parent block. Is there any way to do this?
Another posibility is to get access to the parent block properties from the blocks in the content area. I've seen people talk about accessing ContentPropertiesStack, but this seems a bit tricky, and I haven't really figured this out.
Has anyone done something similar?