As we learnt about the renderings in the last blog, we saw that for dynamic binding of renderings we need placeholders. Placeholders will help us to make the website as dynamic as possible but with this flexibility we might increase the chances of error as well so we will need to configure some settings so that with the restrictive model we can take advantage of placeholders as much as possible.
Now we will understand why we need placeholders and placeholder settings.
If we don’t use the placeholder then each component we need to statically bind to the Layout. If this is a case then the flexibility to change the page design with minimal efforts is lost. So we are using placeholders to dynamically bind the components/renderings to the layout as we saw in the Controller rendering. Now you will have a doubt that we did dynamic binding then why we need placeholder settings.
Let’s understand this in detail. Now you as a developer have setup Controller rendering using a placeholder key ‘main’. When the content Editor is trying to edit (Remove the rendering) it in Experience editor, s/he is not allowed and dependency comes back to you. To remove this dependency, we need to create placeholder settings so that content editors can make a full use of the experience editor.
Let’s examine the scenario we discussed.
- Go to the Test Item (/sitecore/content/Home/Test Item).
- Click on Publish tab >> Experience editor.
- There is no placeholder setting for ‘main’ is present.
- Click on View tab >> uncheck Editing >> Check Designing checkbox.
- Now hover on the Controller rendering part and click on it.
- If you see most of the options are disabled. To enable these options we will need to create main placeholder setting.
- Go to the Content editor tab.
- Navigate to Placeholder settings (/sitecore/layout/Placeholder Settings).
- Right Click >> Insert >> Placeholder
- Name it ‘main’ and Click OK.
- Reload the Experience editor. Hover on Controller rendering part and click on it.
- Now the options are enabled. Click on the Delete option and delete the rendering.
- Now if you again click in the area of the component. You will see an Add here option. Click on that button.
- It gives us an ability to add any rendering. This can be the possibility of error as the content editors will not be familiar which one to be used. So we need to give them only few no. options to be used in one placeholder.
- Again switch to Content Editor. Navigate to main placeholder setting. (/sitecore/layout/Placeholder Settings/main)
- Click Edit under Allowed Controls field (second field).
- Select Controller rendering and View rendering in the pop up.
- Click Ok. Save the changes.
- Reload the Experience Editor.
- Click on Add here button. Now you will be able to see only 2 options. This minimizes the error that content editor can cause.
- Select any of the component/rendering you wish to assign and click Select.
- Save the changes. Publish Test item.
- Browse http://learningsitecore/test-item
This completes the placeholders and placeholder settings. There is one more concept of dynamic placeholders that we will go through now. Till now we have learnt Static binding, Dynamic binding, Placeholders, and Placeholder settings. The placeholders which we learnt can be known as Static placeholders as the key will remain same at any given time.
In the next blog, we will learn about the dynamic placeholders and it’s importance.
Thank you.. Keep Learning.. Keep Sitecoring.. 🙂