Skip to main content

Posts

Add contextual code to an item in Sitecore

One of the most useful customization of Sitecore is the ability to add contextual code to an item in Sitecore. For example let say we have a page in Sitecore that works well in the English language. A content author wants to create the same page in french. Unfortunately there isn't an out of the box way to copy the English page content (including all child items) into french.  This is where adding contextual code will help.  To do this you would have to install Sitecore powershell extensions. There are lots of documentations  online about this tool.  To add contextual code to an item in Sitecore, you would need to add a new module to the powershell script library located at /sitecore/system/Modules/PowerShell/Script Library/ Under this module you can add any powershell scripts you want under the context menu node.  Make sure to enable the module and you should see these script under any item. You can even modify the rule section to d...
Recent posts

GlassMapper

 How GlassMapper works  Glass Mapper is an object relational mapping (ORM) tool in Sitecore. It maps Sitecore items to strongly-typed classes. This makes it simple to access Sitecore data within C# code. Without an ORM, Sitecore developers would need to write and manage a lot of mapping code.  Below are example files that you can use. You have an interface class file, a class file that implements the interface and lastly you can use this in your cshtml file.  That's it. Happy Sitecoreing! IMySitecoreItemName class file namespace Your.NameSpace { [SitecoreType(TemplateId = Templates.MyTemplate.IdString, AutoMap = true)] public interface IMySitecoreItemName : IMySitecoreModel { [SitecoreField(FieldId = Templates.MySitecoreItem.Fields.MyField1)] string StringFieldName { get; set; } [SitecoreField(FieldId = Templates.MySitecoreItem.Fields.MyField2)] bool BoolFieldName { get; set; } } } Use it on your .cs file ...

Create Object XML while Debugging in VS

 There are times when you put breakpoints in Visual studio and read object values within Visual Studio. This is all good if you are doing some debugging. But if you want to save an object like a Json object in Visual studio there isn't a straightforward way to do that. I found this piece of code that I copied and pasted in the Immediate Window in Visual Studio and was able to save the object as an XML file. (new System.Xml.Serialization.XmlSerializer(YourObject.GetType())).Serialize(new System.IO.StreamWriter(@"c:\tmp\YourObject.xml"), YourObject) Happy Sitecoreing!

Install Brightcove Sitecore connector 10.1 and above

Brightcove Sitecore connector 10.0 and below use the Media Framework which is depricated by Sitecore. Brightcove Sitecore connector 10.1 and above instead using the Data Exchange Framework .  Before starting these steps, take a note of a few video pages in the environment you are setting up. That way you can refer to these pages after the upgrade to make sure these videos pages continue to work. Follow these steps in the following order.  1. Install the Sitecore Installation package: Data Exchange Framework 6.0.0 rev. 01537 via Sitecore installation wizard.   2. For CM just package install would be sufficient (Takes around 30 min). For CD we would need to copy files (unzip the package and copy the files in the "Files" folder) over.   3. Run Cleanup script migration-cleanup.ps1 from root Sitecore site. This script is found in the full source code download of the connector.  4. Install Brightcove Video connect package [example: Brightcove.Video.Connect....

Sitecore IP Geolocation

 To setup Sitecore IP Geolocation functionality, you must go to the Sitecore Support & Self Service portal and sign up for a subscription. Refer to this Sitecore article  for more info.  After we have subscribed to the Sitecore IP Geolocation functionality to validate it we use the TestIP.aspx page. Check out thie Sitecore support page to get the TestIP.aspx page and upload it to the Sitecore folder on your server. Open the https://hostname/sitecore/TestIp.aspx page Sample Test IP's to test with:  Africa IP : 102.129.96.0 US IP: 69.162.81.155 UK IP: 101.167.212.0 Make sure the response from the TestIP.spx has the correct country for different test IP's. Once this works we know that the Sitecore IP Geolocation functionality is enabled.  How do we use this functionality in our application.  Just use the personalization rules in Sitecore under the "Geo IP" section (see image below) . So you can control what content is shown to a user based on the...

Updating Sitecore Image alt text

One of the most important conditions of making a site accessible is to make sure that all images on the site have the alt field with some value that describes the image. The simplest update we can make to Sitecore is to have the alt field automatically get the image file name. That way even if content authors forget to fill the alt field, it is pre-filled with the file name. To do this just add $name to the alt field in the standard value of an image [/sitecore/templates/System/Media/Unversioned/Image/__Standard Values] This is all good for an future images that gets uploaded to Sitecore. But what about all the existing images. For that we can write a PowerShell script (see below) to get all images in the Sitecore image folder that have empty alt tags. Export that to a csv file. $pathOfImages = "master:/sitecore/media library/MyImages" $images = Get-ChildItem -Path $pathOfImages -Language * -Recurse | Where-Object { ($_.Fields["Alt"] -ne $null) -and ($_.Fields...

Local Sitecore 9 install

This is a post of my experience installing Sitecore 9.2 locally. Make sure you having the following pre-requisites 1. Operating system - Windows server 2016+ or Windows 10 64 bit. 2. Install Solr 7.5.0 locally 3. .NET Core 2.1.7 Windows hosting module  4. .NET Framework 4.7.2 I use this site to verify and update 5. Turn on Windows IIS and .NET 4.7 features (refer image below) 6. IIS version 10+ 7. Microsoft SQL Server 2016 SP2+. Make sure to have a valid username/password to create and manage sitecore databases. I then installed Sitecore 9.2 by using the new Sitecore Install Assistant (SIA). I downloaded the Sitecore 9.2 graphical setup package for XP single and ran the setup.exe file as an administrator. I referred to the this blog post for the installation steps. Make sure to have the following handy before starting the installation: - Sitecore license fie path: - Solr installed at: example: https://solr:8983/solr/ - Solr installed file path: example: D:\solr\so...