You can make use of the Parameters
field on the View/Controller Rendering templates to pass in some additional values and then use these in your View/Controller to then run whatever logic you need.
You still need to create 3 Rendering definition Items in Sitecore, but they can all point to the same View/Controller, but with the different parameters updated. On the View Rendering/Controller Rendering, set the Parameters
field as required, e.g.:
Parameters:
CssClass=special-highlighting&ExtendedInfo=true
Then in your code you can access these parameters:
@using Glass.Mapper.Sc.Web.Mvc
@using Sitecore
@using Sitecore.Mvc.Presentation
@model MyProject.Data.Interfaces.IGenericContent
@{
RenderingParameters parameters = Sitecore.Mvc.Presentation.RenderingContext.CurrentOrNull.Rendering.Parameters;
string cssClass = StringUtil.GetString((object) parameters["CssClass"], "default-class");
bool showExtendedInfo = MainUtil.GetBool(parameters["ExtendedInfo"], false);
}
<div class="row @cssClass">
<div class="large-12 columns">
<h2>@Html.Glass().Editable(Model, x => x.Title)</h2>
@Html.Glass().Editable(Model, x => x.Text)
@if (showExtendedInfo)
{
@Html.Glass().RenderImage(Model, x => x.Image)
}
</div>
</div>
(The above example is using Glass Mapper, but it is not a requirement.)
The code is using Sitecore Helpers to set a default value if none has been set in the Parameters
field. You can do something similar from your Controller as well.
Since you have 3 different Rendering Item definitions, you can restrict which rendering can be used in specific placeholders using Allowed Control restrictions.