3 December 2014

Overwritting Placeholder settings on specific templates

On a previous post, I was talking about how to create a placeholder which will allow certain controls only. For that we had a 2 Columns Renderings (Main Column and Side Column) which had the following Markups and placeholders



    < div class="row">  
        < h1 class="col-sm-12">@Html.Sitecore().Placeholder("imagebanner")< /h1>  
    < /div>  
      
    < div class="row">  
         < h1 class="col-sm-12">@Html.Sitecore().Placeholder("contenttitle")< /h1>  
    < /div>  
    < div class="row">  
        < div class="col-sm-9 main-column">  
            < article class="col-sm-12">  
                @Html.Sitecore().Placeholder("contentcolumn")  
            < /article>  
        < /div>  
        < div class="col-sm-3 sidebar">  
            @Html.Sitecore().Placeholder("sidecolumn")  
        < /div>  
    < /div>  


As we saw, it was quite easy to define our Sitecore placeholder settings and allow a few controls:



Well this was really nice and handy if your templates using the 2 Columns Rendering should allow all 4 renderings: Rich Text, Image, Navigation, Related News. BUT... What if some of your templates should only allow 1 rendering? In the news content page for instance, you want to allow only the related news panel. Creating a new rendering with a different placeholder key??? no way.... Well, good thing sitecore thought about this. You can overwritte the placeholder through the presentation:

1- Define a new placeholder in Sitecore. This new placeholder will be exactly the same as per the first one Except:
  • Having a different Key: the key must be unique, so you have to use another key
  • Instead of allowing the 4 renderings, we will only allow 1: Related News Panel


2- Edit the template - or item you want to have different settings in the placeholder:

In this example we will edit a specific item but you can do it at the template level:
  • Select your item.
  • Go to the presentation
  • Select the placholder settings 
  • Click edit
   
  •  When editing, you can select "Select Existing Settings" on the Left hand side and then Select our new placeholder settings. Make sure the Placholder Key correspond to the key you were using previously


You can now save everything and go to the page editor. You will notice that on the placeholders you will not see "SideColumn" but "NewsItemSidePanel". Then if you add a new panel, you will notice only the related news panel is available:



No comments:

Post a Comment