Posts

Showing posts with the label sitecore

Using React components in Sitecore

Image
  PROBLEM BACKGROUND Do you need to incorporate a React component into Sitecore?   Is your team using SXA or a similar technology which provides out of the box components that your building your site with?   Are you NOT using Sitecore JSS / headless yet?  We are developing a new site in Sitecore 10.  We wanted any component that interacts with our CRM data to be written in React.   We are NOT using Sitecore JSS but we are using Sitecore SXA.  The question becomes,  how can we incorporate a new Sitecore rendering that will use React as the front end technlogy.  How will we get the rendering and datasource parameters successfully passed down to the React component? One approach I've seen on several Sitecore sites, blog posts, etc is to use ReactJS.Net.    That solution works but feels like overkill to include a React component.   You get to maintain ReactJS.Net components in your solution, You need to have ja...

Always enforcing your sites single language in Sitecore

PROBLEM BACKGROUND Do you have a sitecore website that will exist in only one language? Have you checked what will happen if someone accesses your site passing the query string parameter sc_lang where sc_lang is set to a value your site doesn't support?   Your site might throw a 500 error, it could redirect the user to your custom error page or it could throw a yellow screen of death. Try your site out, see what happens.      You might be wondering why would this ever happen? I became aware of this issue when one of our designers tried to pass an unsupported language to the sc_lang parameter to see what would happen.   Our site redirected the user to our error page, showing no content. We all know malicious users exist.  If they find you are running a Sitecore instance, they can try to pass query string parameters to your site to see what happens. If they get the ysod they might get useful information. POTENTIAL RESOLUTION Keep in mind, S...

Handling the situation where scItemPath does not exist in Sitecore MVC

What happens if the scItemPath specified in your route does not exist in Sitecore? In this post i'm going to discuss how I handle this situation. Here is a sample route from Sitecore's MVC documentation .   (see Section 4.1) // matches the item '/home/blogPosts/{blogNo}' routes.MapRoute("example2", "blog/{blogNo}", new { scItemPath = "/home/blogPosts/{blogNo}" }); But what happens when the blog number doesn't exist?   What page will Sitecore show?  What if the user has a link to an old blog post that you have archived or someone links to a blog post using the wrong number by accident? What I wanted was a new route value that specified where to go when the path resolved by scItemPath is not found.  So I created the scNoItemFound value. // matches the item '/home/blogPosts/{blogNo}' routes.MapRoute("example2", "blog/{blogNo}", new { scItemPath = "/...

Using Sitecore.Logging to send emails

BACKGROUND In this post I will show you how to send an email using the Sitecore.Logging namespace. If you want to get straight to the code here you go ! PROBLEM WE NEED TO SOLVE Do you need to send emails when something happens in your Sitecore website?  For example, if you get a critical error and want to email this to a distribution list?       Using Sitecore.Diagnostics you can log this error to the Sitecore log, but you still need that email sent to get someone working on the issue asap! Many solutions exist to fit this need.  You can use System.Net, you can use nLog or a plethora of other logging systems. But why not use what you already have with Sitecore?    Sitecore went ahead and wrapped up the log4net code inside their own dll,  Sitecore.Logging.dll.    You can use your favorite .NET decompiler to look at the code.    I use Telerik's Just Decompile to look under the hood of the Sitecore.Logging.dll.   ...

Conditional caching components in Sitecore MVC

Image
I'm writing this post to help remember why I chose a particular solution and to hopefully help anyone else in the same scenario. I will start off by stating the problem I needed to solve, a couple options I reviewed and why I chose a particular solution.  We are using Sitecore 7.0 and since Sitecore 7.0 requires ASP.NET MVC 3 we are using ASP.NET MVC 3.   We are also using Glass Mapper and love it :-). PROBLEM:    Users came to me with a late requirement.  They want the ability to add renderings above and below an items content.   The renderings they want must access the database each time they are rendered to show accurate data. How can we efficiently handle this situation without making major changes to the current design? BACKGROUND:    Our items are made from a template that has four sections.  (Other sections exist but for this discussion these sections are the only ones relevant).   Each section consists of the followin...

Speeding up our website - My experiences with Sitecore

Have you ever ran YSlow or PageSpeed against your site and you get poor grades in the following categories Make fewer http requests Minify javascript and css Compress components with gzip. Our site got poor grades for these items and my initial response was who cares.  Bandwidth is almost unlimited anymore and we are conditioned to sites taking a few seconds to load. I had this who cares attitude until I started actually profiling our site and realizing that minimal changes could make a big difference in user experience.   Instead of our site taking 5 - 8 seconds to load it could take less than 5 seconds to load. Also, as a developer I typically never involve myself in the http request pipeline from the browser perspective.  I'm abstracted from that, especially being a .net developer, we are abstracted by many things.    But, making the site perform well from a browser perspective is just as important as making your code algorithms perform we...

Displaying shared content across multiple Sites

Sitecore does a great job of separating content from the presentation of the content. This is the main selling point of any CMS tool, but Sitecore does an excellent job of allowing this to happen. What I found not intuitive in Sitecore is the ability to display shared content. PROBLEM For instance, assume you have stories which live outside of the context of any site site. The stories can be tagged with specific categories, where each category associates to a different web site. (ok, this is a simple example, but follow me here). So you have the following structure in your sitecore tree /sitecore/content/site 1 .. [all of the nodes that make up the site] /sitecore/content/site 2 ..[all of the nodes that make up the site] /sitecore/content/Stories 2010 January Story Item 1 [category = site 1] Story Item 2 [category = site 1 and site 2] February Story Item 1 [category = site 1 and site 2] ...etc [you get the picture] POSSIBLE SOLUTIONS Wh...

Saving extra data to a sitecore field

We use the Shadowbox component on our web site. How we use the shadowbox is whenever an image is displayed the user can decide if they want the image to be clickable to open up a video or other media content (podcast). In our first web site in Sitecore the users had to put the shadowbox parameters inside the html. This was not a good seperation of presentation and content. But our first site had to be up quick, so we went with the easiest albeit harder to maintain approach. Now the users groan whenever they have to enter parameters for a shadowbox link or other html that they must enter into the content. So the goal for our future sites is to seperate presentation from content as much as possible (and have exceptions when necessary). After batting around a few ideas on how to implement the shadowbox parameters needed into Sitecore I came to the following conclusions: I did not want to add a new field type, that would require too much work. I'm pretty lazy :). No, actual...