Hiding components from users when they are not logged in. AKA Personalisation and you!
When you first install Sitecore 7.2 this is the page that greets you:
However for this example, let’s make it so that users that aren’t logged in can’t see the title and body, until they are logged in they shouldn’t be welcomed to our system.
While this is a silly example, the same mechanism can be used to achieve many other requirements, such as show specific content based on the users location, goals that have been set, or perhaps hiding welcome content after they have already used the website.
To make this even better, the rules engine is easily customised such that you can create custom rules based on applicable business requirements such as if the user has a certain attribute in their profile.
- Firstly, we need to make sure that analytics are enabled, personalisation is driven through the analytics engine and requires it to be turned on
- Log into Sitecore, go to the content editor and select the Home item.
- In the menu select Presentation and Details
- Under Sample Layout select edit
- In the Device Editor select Controls, then Sample Rendering and click Personalize.
- In the Personalize the Component window click New Condition
- Name the condition “Hide for Anonymous”
- Under the “Hide for Anonymous” condition click Edit
- In the rule editor, find the Security rules and click on “where the current user is anonymous” and click ok.
- Back on the Personalize the Component window to the right of where we clicked edit, check the “Hide Component” tick box.
- Publish the home item.
If you open an incognito window or clear your cookies and go to the home screen you will get this cold unwelcoming page:
NOTE: To quote the great Stan Lee “With great power there must also come- great responsibility”, whilst the rules engine allows you to tailor content you must be careful to not over personalise and create content that is never seen because you have too many rules chained together or have catch all rules.
Now go forth, create custom rules and amazing websites.