In this blog I will
explain how you can personalize a widget ( user control ) content based on
specific code or variable with giving the ability to sitecore content editor to
add, update and delete this personalization.
We will use a built in
sitecore feature called personalization
using a rule engine ; under sitecore you will find many personalization rules
based on different criteria like engagements plans and goals.
If you visit Walkthrough
personalizing components Personalize the content you will find a detailed information
about different personalization topics.
So what if you need to
data source you user controls based on the visitor location ( country , city...etc
), and let's suppose you have this location saved in a variable or a cookie; so
maybe you can just apply an if statement on that variable and based on the
value you switch the data source item for this user control! yes it is a solution
but is that enough?!
Of course using the above
technique means that at each time user need to update a data source you will
need to update your code and redeploy, Also if user want to add a new location
with a new data source you will need to
add it using code or configuration and
redeploy it!
It seems that the above
is not a complete solution so by using sitecore personalization rule and not
the build in rule I will show you how to build custom rule or condition.
All what you need to do
are the following:
- Adding new class that will evaluate you sitecore condition as following:
- Under sitecore go to "/sitecore/system/Settings/Rules/Definitions/Elements/GeoIP"
- Add a new condition as in the following screen shot:
- In the new condition fill the Text field with " where the user location[operatorid,StringOperator,,compares to] [UserLocation,Text,,region name] " and the Type field with your class path and class dll as ( Mydll.UserLocationCondition , Mydll ).
- Now go to the page you want to personalize it's Sublayout under sitecore, select the required Sublayout click personalize.
- Click "New Condition" and enter a name as you can see in the following screen shot:
- New click on Edit condition and select the condition that we already created above and update the compare to and region name variables as you can see in the following screen shot:
- At the end you just need to select your content data source if the above condition is true, you can select a data source as you can see in the following screen shot:
I hope the above will help.
No comments:
Post a Comment