Hiding unneeded Components to speed up Sitecore Experience Editor

Sitecore Experience Editor is very powerful but if you have lots of components on a page it can be slow to load sometimes. Because of this as a Sitecore developer you often find yourself looking at what you can do to speed it up. The first steps are usually to ensure you are following the recommendations in Sitecores Performance Tuning Guide. Also in more recent versions of Sitecore such as Sitecore 8.2 there are improvements in the performance of Experience Editor by Lazy Loading components in the Ribbon and so on – so if upgrading in the immediate future is an option this is recommended. If it isn’t and you are stuck on Sitecore 8.1 then also look at the following potential improvements: Disabling the My Items count (there is also a Support Hotfix for this now) and turning off the Suggested Tests count.

What else can I do to speed up Experience Editor?

So as the title of this post suggests we can also look at hiding components or partials that are not needed during Experience Editing. This might be things like a Google Tag Manager partial, Social Share Buttons or in our case ReciteMe and a partial that got a list of notifications from a 3rd party feed. These are all things that don’t need to be loaded when using Experience Editor and add to the page load time.

Show me the code

There are a number of ways to do this but since were using Sitecore MVC it seemed nice to do it with an MVC FilterAttribute. Create a class with the following code:

using System.Web.Mvc;
public class ExcludeFromExperienceEditor : FilterAttribute, IActionFilter
{
public virtual void OnActionExecuting(ActionExecutingContext filterContext)
{
if (Sc.Context.PageMode.IsExperienceEditorEditing || Sc.Context.PageMode.IsExperienceEditor)
{
filterContext.Result = new EmptyResult();
}
}

public void OnActionExecuted(ActionExecutedContext filterContext)
{
// Not required
}
}

This uses the inbuilt Sitecore PageMode.IsExperienceEditorEditing and PageMode.IsExperienceEditor to check if Experience Editor is being used. It then returns an empty view result to the controller.

Then decide which of your components and partials are not needed in Experience Editor and decorate their controller actions with the new FilterAttribute like so:

public class GoogleTagManagerPartialController : BasePartialController
{
[ExcludeFromExperienceEditor]
[ChildActionOnly]
public ActionResult Index()
{
//code removed for simplicity
}
}

Thats all there is to it. You can exclude as many components in this way as you like very quickly and you should see some performance gains from doing so. Just make sure you don’t accidentally exclude anything your content editors need to see when editing the page!

Feel free to tweet me or leave a comment if you have other ways of doing this or some improvements.

Simple Sitecore Content Synchronisation with Sitecore Content Migrator

As a Sitecore developer you often find you need to keep Dev and Staging environments up-to-date with Production in order to aid in development and in support and maintenance – otherwise it is very hard to successfully develop and test new features or replicate an issue from Production locally.

This used to mean manually backing up and restoring databases or creating Sitecore Packages to pull content down. This process is a labour intensive and error prone as well as a pretty daunting task :-(.

Sitecore Content Migrator to the rescue

migratorThankfully Jeff Darchuk created Sitecore Content Migrator back in October to do just this for you.

Sitecore Content Migrator is a free tool for Sitecore Sidekick which allows you to quickly and easily sync content down from one environment to another. It’s pretty simple to install and setup and then can be used whenever you want to carry out a sync.

It uses the same underlying technology as Unicorn (Rainbow), is pretty rapid and gives you some nice updates on progress along with a preview feature – so you can check all the changes before you run the import for real.

Installing & Configuring Sitecore Content Migrator

  1. First you need to install Sidekick itself. You can do this with the Sidekick Sitecore Module using the Sitecore package installer (https://marketplace.sitecore.net/en/Modules/S/Sitecore_Sidekick.aspx) or instead use NuGet to install it like so from Vistual Studios Package Manager Console:

    Install-Package SitecoreSidekickCore -Version 1.0.0.

    Ensure you install this on all environments you wish to pull content from as well as the environments where you will use it. This is because the service used by the Content Migrator must also exist remotely.

  2. Once you have installed the module you should find it has also installed 4 new config patch files (zSCS.config, zSCS.Aduitlog.config, zSCS.ContentMigrator.config, zSCS.Editingcontext.config). The one you want to edit is zSCSContentMigrator.config.
    Alter the servers list to include the environments you want to pull content from, in our case Production and Staging:

    <servers hint=”raw:BuildServerList”>
    <server>https://production.yoursite.com</server>
    <server>https://staging.yoursite.com</server>
    </servers>

Time to Sync

  1. Go to an environment where you want to sync content to. Click on the Start button and open Sitecore Sidekick. Then click on ‘Content Migrator’:
    sidekick-dashboard
  2. Select the server to pull content from (e.g ‘production.yoursite.com’), then browse the content node and select the content you wish to sync.
  3. Then check any of the following options to sync all content down and update the local site:
    –  ‘Migrate all children of selected item’
    –  ‘Overwrite all existing content with new content from the server’
    –  ‘If parent doesn’t exist locally add that too’
    –  ‘Make local content tree mirror the remote content tree’ Note: Jeff confirmed to me on Slack that this maintains the existing Sitecore IDs. So this is great if you use Unicorn and don’t want to mess up Dev content IDs.
    –  ‘Run using the event disabler’
    –  ‘Run using the bulk update context’
    Further information on these options and what they do can be found here: Sitecore Content Migrator
    content-migrator-step0

  4. Click the ‘Preview’ button
  5. Check that everything looks ok
  6. Click the ‘execute this operation’ button.
  7. Monitor the import and check that it completes successfully – look under the ‘Currently Running Operations’ section.
  8. Publish the site
  9. Test the site works as expected in your environment
  10. Rejoice as not having had to do much

Suggested Improvements

  • It would be really good to support automated scheduled syncs either by setting this up in config or saving an migration config. – I’ve already suggested this to Jeff and he’s logged it as a feature request.
  • It would also be cool to be able to sync multiple root nodes, e.g content and media library items at once.

All in all this is a great tool for making content syncs a whole lot simpler and allowing you to concentrate on development instead of manually keeping your environments in sync.

Simple Markdown Support In Sitecore

Markdown is a really lightweight way to support simple HTML formatting, such as bold or italic without using a Rich Text editor. It’s often used in ReadMe files and sites like Stack Overflow. This post describes how we can also use it with Sitecore with just a few lines of code, you can read more about Markdown on the John Grubers blog.

What is markdown and why would I want to us it?

So why might you want to add support for simple formatting to plain text fields in Sitecore?.

You might want to do this because you have a text field which you don’t want content editors to be able to use full rich text editing with, but you want to give them a bit more control over the styling. You might also do this the make it quicker and simpler for content editors.

In the example I’m going to explain here we wanted to use Markdown to allow the Content Editors to bold part of the text in a single line text field but not all of it. In this case the price.

markdown-hero-example-crop

Markdown works by wrapping the plain text with punctuation characters such as “*” or “#” in order to apply html tags to the plain text when it is rendered.
e.g when rendered out this:

##Title Of  Section##

becomes this:

<h2>Title Of Section<h2>

How do I do this?

The first thing you will need is a mechanism for processing the Markdown within your text. You could write your own Markdown service and return the processed text. However since others have already been through the effort of doing this It makes sense to use them.

Installing a Markdown NuGet Package

I spent some time researching into different options and decided upon MarkDownDeep. It’s quick, supports most Markdown features and can be installed via NuGet from here: https://www.nuget.org/packages/MarkdownDeep.NET.

Install this into your project as follows in Visual Studio Nuget Package Manager Console:

Install-Package MarkdownDeep.NET

Once you have done this you need to create a HTML Helper Extension that is going to be used in our views to process the Markdown.

public static class HtmlHelperExtensions
{

public static IHtmlString Markdown(string text)
{
Markdown markdownTransformer = new Markdown();
string html = markdownTransformer.Transform(text);
return new MvcHtmlString(html);
}

public static IHtmlString Markdown(this HtmlHelper helper, string text)
{
return new MvcHtmlString(Markdown(text).ToHtmlString().Replace(“<p>”, “”).Replace(“</p>”, “”));
}

}

Using Markdown in a Component

The next step is to add this to a view, we’l use an example of a simple Sitecore MVC Hero component here. Create a view with the following content and add it to Sitecore in the usual way:

@using Glass.Mapper.Sc.Web.Mvc
@using Sitecore.Mvc
@inherits GlassView<Custom.Models.Renderings.Hero>
<section class=”hero”>
     <div class=”hero-inner”>
             <h1>
              @Html.Glass().Editable(x => x.Title)
              </h1>
              <p>
                 @if (IsInEditingMode)
{
       @Html.Glass().Editable(x => x.Text)
}
else
{
       @Html.Markdown(Model.Text)
}
              </p>
       </div>
</section>

The important part here is: @Html.Markdown(Model.Text), this processes the Markdown and renders it.
You may notice that here we are using Glass Mapper (http://www.glass.lu/), however this would work in the same way with standard Sitecore MVC. We also do a check (using IsInEditingMode) to see if the page is being edited in Experience Editor before we render the Markdown.

Adding Markdown in Sitecore

Once you’ve done this then you can test it works by going into your component in Sitecore Content Editor and adding double asterisks (**) around part of the text like so:

hero-markdown-example-sitecore

This will make it bold. You could also use a single asterisks (*) to make it italic. You should also be able do this Experience Editor if you wish.

The Final Result

Once you  have saved this update and view the page with your component on it you should see something like the following:

markdown-hero-result

If you look at the HTML you will see it doesn’t contain the ** around the £99 anymore and instead has been converted to: <strong>£99</strong>

The full rendered markup for this example should be as follows:

<section class=”hero”>
         <div class=”hero-inner”>
<h1>January Sales Now On</h1>
<p>Prices starting at <strong>£99</strong> each</p>
          </div>
</section>

We have used this on a number of components and it works really well. Hopefully it will be useful for you too.

Sitecore Stack Exchange Site Needs Your Help!

A while ago Mark Cassidy  started a Stack Exchange Site for Sitecore – our own Sitecore Specific Stack Overflow essentially .  Great idea right?

The Sitecore Stack Exchange Site Needs Your Help!
Calling All Sitecore Developers!

Myself and other Sitecore Community members have been trying to get the site (currently in Beta) to launch.

Due to Sitecore Symposium causing a downturn in activity for over a week we were initially told the site wasn’t going to make it out of Beta :-(.

However the good news yesterday was that Stack Exchange kindly relented and extended the Beta for another two weeks! until the 18/10:

http://meta.sitecore.stackexchange.com/questions/60/extending-the-private-beta-to-10-18

However if this is going to succeed we need more Sitecore developers / users to get involved. There are many of you out there but not enough on the Stack Exchange site.

If you have already signed up for Area51 then please use the site and start contributing.  Go to: https://area51.stackexchange.com/proposals/101710/sitecore and then use the “Visit” link under the “20 days in Beta” box, Or use this link: https://area51.stackexchange.com/proposals/101710/sitecore/visit and log in with the same details you used for Area51

If you haven’t already signed up, then ask for an invite in the #stackexchange channel on slack or tweet me @billyjava and someone will send you an invite.

I’m sure you will agree that our own Stack Exchange site for Sitecore would be a great asset to the Sitecore community and an really useful platform to share knowledge and documentation but if we don’t quickly get more support it won’t make it.

So please do what you can to help and support by asking and answering questions on the Beta site.

 

Sitecore Symposium 2016 – Day 1

Sitecore Symposium is an 2 day Conference for Sitecore Users, Developers, Partners, MVPs and just about anyone else who works with Sitecore.

This year it was in New Orleans and I was lucky enough to be able to come out for a few extra days to Explore NOLA and I can highly recommend it, a great city with some insanely good food, interesting history and friendly people.

img_9704

Day 1

On day One I was to learn a lot about the improvements and new features in Sitecore 8.2 including SXA, Sitecore Azure, Path Analyser and much more.

Opening Sessions

The opening session was kicked off in New Orleans style with an big Jazz band which certainly woke me up after the early start.

Interesting it was comedian Jake Johannsen who opened up and got us all in the mood before handing over to Micheal to kick off the first keynote.

img_9489

Micheal talked about empowering Physical and Digital experiences for customers and bought various users of Sitecore onstage to discuss how they are using Sitecore. Danone discussed the personalisation that they have done on their Baby early life platform for mothers and how they have used Sitecore to power this. It was really cool to see someone leveraging all the personalisation, profiling and automation features. Danone have seen an 800% uplift in sales from this. Their tips were: Build data first, start now and don’t wait for the tech to all be there to do it.

img_9492

One of the most interesting things shown was Sitecore Experience Accelerator (SXA) which allows you to create a new site in Sitecore, Wireframe it, Add Content, Export the wire frame and import a theme for it. It is Responsive out of the box and could be a really quick way to stand-up a Sitecore site quickly. I would learn more on this later.

Micheal announced that Sitecore has now built commerce in out of the box and it is fully integrated and supports personalisation. This is great news for those with Commerce aspects to their Sitecore sites.

Next up was Jason Silva who is a Technologist & Futurist. He was very engaging and had some interesting ideas about the future of Nueroscience and Nano Technology, ‘Hacking Life Itself’ and how Tech evolves exponentially. He made me re-think the barriers between tech and science and ‘Playing God’ stating that ‘There is no duality between nature and technology, they are 1 of the same’.

img_9505

Developer Keynote

Lars Nielsen took to the stage to share some information on Sitecores product strategy. He talked about xConnect and oData which are coming soon and will provide much better APIs for working with data in Sitecore. He then discussed Express Migration Tool which allows you to go from Sitecore 7.2 to Sitecore 8.2 in an automated manner.

img_9511

He touched on the NuGet feed that is now available for Sitecore, I think this is the thing most developers have been waiting a long time for (I saw a whole lot of Tweets about it when it was released a few weeks ago). The Official Sitecore Nuget can be found here: https://sitecore.myget.org/gallery/sc-packages.

img_9509

Lars introduced Antony Hook who talked about how Sitecore manages new feature requests using ProdPad and the ways in which these requests get to the Sitecore product team. Great to hear they are opening up user voice to non MVPs https://sitecore.uservoice.com/ and about the new Stack Exchange http://sitecore.stackexchange.com that is nearly out of Beta.

img_9524

img_9531

One things for sure Sitecore’s Community is huge and growing every day, just look at the stats above!

We also heard about Helix (the new name for the the design principles that underpin Habitat) http://helix.sitecore.net/. More on this later.

img_9518

We also saw a quick overview of Sitecore Path Analyser which looks great, I watched a demo of this by the Sitecore Product team in the Partner Pavilion and was impressed by the UI and functionality it provides.

img_9494

 

img_9560

Azure Sessions

It was the time to attend the first of the developer sessions and I chose two on Azure since this is something I’ve been looking at recently.

img_9535

The first was Sitecore in The Cloud: Architecting in AWS vs Azure where Peter Petley shared some info on his recommendations for deploying Sitecore to the Cloud. He talked about the performance of AWS vs Azure and I was surprised to learn that Azure performs better in general.

img_9539

He also talked about some of the new features for Azure that will be supported in Sitecore 8.2.1, more on this later.

img_9540

img_9543

One of the key takeaways here was the Paas doesn’t really work properly (there are reliability issues with some modules etc) so Iaas is still the way to go. Redis Cache was also recommended due to it’s great performance.

img_9548

 

img_9549

The above slides are a nice little summary of which platform wins out.

Next up was Ciaran McAuliffe’s session: Better Together: Sitecore on Azure. He dove into the Sitecore 8.2.1 Azure dashboard and showed us the power of App insights with things like Sitecore Logs, APV Map, Server Responses and Rules.

img_9553

Ciaran explained how Azure search is used instead of Lucene and that for cost and performance reasons you should only setup the indexes you need and use (not all Sitecore indexes in the configs).

Sitecore 8.2.1 comes with Data Packs out of the box that will pre-configure Azure for you, there is no need to use the Sitecore Azure Module anymore – it is being phased out. There will be Data Packs for CD and CA servers and everything will be setup for using the web deploy engine. The automation scripts are JSON based and ARM Templates will be provided xDB, XP etc to build out environments and the resources required as a base level for each.

img_9555

There are parameters files that go along with the ARM Templates that define the various variables, essentially 2 JSON files and an Powershell script is all that is needed to deploy Sitecore to Azure.

img_9554

We were shown the different plans that can be used for the various services required to run Sitecore on Azure he also discussed how Sitecore are also working on GeoLocation in Azure and using Slots to allow for environments to be replicated easily (e.g Staging and Production).

This all seems like a vast improvement to the current Sitecore Azure offering and should greatly simplify the process. It should be available from January 2017 so well worth waiting for if your looking to move to Azure soon by the looks of things.

SXA – Sitecore Experience Excellerator

After a spot of (excellent New Orleans style) Lunch I went to see Kerns talk on SXA – Sitecores new offering to get you a Sitecore site up and running very quickly. I’d heard a lot about this and it sounded very interesting so was keen to find out more. It is installed as a separate package in Sitecore . It is installed as a separate additional package in Sitecore with an associated costs a percentage of the Sitecore license.

img_9564

SXA allows you to create a new Site from within the Sitecore Content Editor Interface (nice). Sites need to be created within a tenant – a business unit with different visitors but which exists within the Same Sitecore instance. Tenants are created first (again within the CE).

Once you’ve created a site you will see it has created a folder structure that follows the Helix principles (from Habitat) so you will see familiar folders here such as foundation and feature.

img_9591

Kern then showed us how pages can be quickly put together using page designs and partial designs and 70+ pre-built components.Standard values are no relied on that much, instead XML is layered to create the pages and dynamic placeholders are available out of the box. The pages built will not have a design, they will look like wireframes, this is intentional.

img_9567

Kern then showed us how the wireframe layout can be easily exported using a button in the SXA toobar, then the zip generated can be provided to an front-end team or 3rd party to style before it is imported back in. Kern demonstrated this by quickly importing a pre-made theme and it automatically styled all of the pages and components. Impressive stuff.

img_9578

We were then shown a bit more detail on how these themes are created. Essentially it uses the 960 grid system so supports mobile out of the box, Bootstrap and Foundation are not currently supported. The themes are made up of individual CSS files, Images and JavaScript but optomised versions of these are served from the Site. Developers can add addtiional classes to the HTML when theming but can not change the structure of the HTML.

img_9579

Kern mentioned a few restrictions around using SXA, all data sources must use Items to us the standard components provided with SXA. However it is possible to build a standard component and use it within a SXA site. It does need to inherit from special SXA specific rendering classes to work.

img_9586

Deployment of a SXA site (assuming no customisations) is just a simple case of publishing the Site. All all this seems a great way to standup a Sitecore site quickly and with limited investment in development. It is perhaps though limited to Sites without the need for medium to high customisation. It will be interesting to see how SXA improves over time as it is something Sitecore are going to continue investing in.

It was now time for me to go and enjoy the beer in the Partner Pavilion and meet a few new people. I was already looking forward to Day 2.

My thoughts on SUGCON 2016 – Day 2

badgeThere was an early start for Day 2 (especially after a late-ish night involving a few strong Danish Beers), but I knew there were some intriguing talks today so didn’t want to miss anything.

You can read about Day 1 here if you missed it.

The first session that caught my interest was Nick Wesselmans talk on how Active Commerce use SIM, Powershell, Octopus Deploy and Azure to automate product builds.

Using SIM, Powershell, Octopus Deploy and Azure to automate product builds.

Nick gave an overview of how they created a PowerShell wrapper for SIM to automate Sitecore instances for product builds for their Active Commerce product.

IMG_5762

He also talked about how they use Sitecore Power Shell Extensions (SPE) to do things like automate publishing, rebuild the links database and initialise Sitecore Zip package builds. I’ve experimented with SPE but I’ve not used it in anger and this has given me ideas for how I might use it more on current or future projects.

IMG_5764

Finally, he talked about their use of Octopus for deployment of packages and invoking PowerShell scripts and Azure IaaS and Azure Blob Storage and AzCopy which is used for quickly spinning up VMs for hosting the product build and test environments. I liked the idea of these being scripted to only run during business hours.

IMG_5768

The Active Commerce team also use Bamboo for their build server (but are thinking of moving to Team City). Nick showed us that their build pipeline looks like this:

IMG_5773

It was nice to see some familiar approaches here, albeit with different tools in some instances and some new ideas too.

You Me and Sitecore MVC

After a short break Kern Herskind delivered and entertaining (and Circus themed) presentation on Sitecore MVC. He even rode a unicycle at the end!

IMG_5777

Kern gave a general overview on MVC for those not familiar with the concepts and then how Sitecore MVC works and whats available out of the box. Not much of this was new to me but it was good get a refresher anyway.

Then Kern talked through some of the downfalls of Sitecore MVC and how he has gone about solving them. Things like renderings not being able to alter any HTML that is rendered prior to them being rendered and multiple form posting issues.

IMG_5781

IMG_5782

IMG_5783

We then go a sneaky peak of what coming up for Sitecore MVC, such as abstract base classes and better ServiceLocator and DI support:

IMG_5869-3

IMG_5873

Kern finished by talking about the future of Sitecore MVC and expectations for the future.

IMG_5787

Good to see better documentation and closing feature gaps on the list of improvements.

IMG_5788

The key message here being that Sitecore MVC is going to continue to be the preferred UI Framework.

Hedgehog then did a quick talk on their TDS product and helped to answer the question a lot of developers might have, “why should I pay for TDS instead of using Unicorn”.  The answer is probably in these two slides, maybe go and show them to your Boss :-).

IMG_5791

Essentially it does a lot more besides just syncing items between sitecore instances:

IMG_5792

I haven’t used it but I’ve head good things about it from other Sitecore Developers.

After lunch (which was excellent by the way) I opted to attend two talks on Sitecore Habitat. One by Ruud Van Falier called Introducing Sitecore Habitat and the 2nd by Anders Laub on Practical Habitat: Embrace the Architecture.

Introducing Sitecore Habitat

For those who don’t know what Habit is, it is an Architecture approach for Sitecore development and is designed to give best practice guidance on how to structure your Sitecore projects. I have taken a look at it a few times but not really used it and the feedback from other Sitecore developers I’d spoken to was that it was quite complicated, so I was interested in finding out more about it.

Ruud was presenting to a packed room with quite a few developers stood up at the back, obviously as keen as me to know more. He started with the basic concepts of Habitat, explaining how all modules are self-contained and that there should be no communication that goes upwards between modules.

IMG_5796

He also explained the the 3 layers of Habitat: Foundation, Features, Projects.

layers

Ruud then discussed examples of elements that might live in these layers and how the dependencies flows downwards.

IMG_5806

He then showed the technology stack, which are probably familiar tools to most of you. Sitecore 8.2,  MVC,  Dynamic Placeholders, Unicorn, Bootstrap, JQuery, Sass and Gulp.

A run-through of the Habitat solution structure then followed and an explanation of the different build tasks used.

build

There was then a more in-depth explanation regarding Modules:

IMG_5816

IMG_5818

IMG_5820

And then more detail on layers:

IMG_5822

IMG_5828

IMG_5832

IMG_5834

Finally, a pros and cons slide and questions:
IMG_5836

Ruud was honest about the fact that Habitat is in the early stages and is changing every day, he also said it’s not meant to be taken as a ‘Boiler Plate’ for Sitecore solutions – more a guideline. However, I left the session will a lot of things to investigate further and will definitely be taking a closer look at Habitat and how some of It’s concepts can be applied to the projects I am working on.

Practical Habitat: Embrace the Architecture

With my appetite now whetted for Habitat I went straight to the next session on embracing the architecture.

Anders talk started with a general discussion around Architecture and then moved to Habitat and why Pentia use it as an architecture for their solution:

IMG_5837

He then dived into a demo of their solution and explained how it differs to the default Habitat setup. I have a video of this somewhere which I’ll try and add here when I get a minute.

He then discussed a few foundation modules they have created and how it really works well for them as an approach.

IMG_5840

Anders took some tough questions from the crowd well (such as the number of projects in Habitat – which is many) and I think by the end of the session most of the room will be taking another look at Habitat.

Ladies and gentlemen start your testing.

Testing in Sitecore can be notoriously difficult and for some Sitecore developers this means that unit and integration tests that involve the Sitecore context or items are sometimes skipped.  I was interested to see if Alastair had some other ways to implement testing and I wasn’t disappointed :-).

IMG_5844

Alastair Deneys ran us through 4 ways in which to Unit test with Sitecore. The first was an interesting one and was to essentially install Sitecore in your application and then run the tests from an asp.net web page test runner.

The 2nd and 3rd were to add a minimal or full Sitecore config files and the Sitecore dlls you need to your nunit test project and run It. This worked pretty well but as Alastair said, isn’t proper unit testing as it’s using real data.

The 4th was to use FakeDb to mock the Sitecore items you need to run your tests. I’d heard about FakeDb before but not used it so it was nice to see an example of how this is done.

IMG_5855

Alastair also showed us how Sitecore.LiveTesting can be used to spin up an instance of Sitecore in a container in the background to test against.

IMG_5856

IMG_5863

It was a bit slow but seemed really cool and definitely something I’m going to experiment with.

IMG_5868

The key message here was, whatever you do make sure you create tests and don’t get hung up on if they are real unit tests or actually integration tests.

Sadly it was now time to head to get our flight home so I missed out on the last talk of the day by Martina Welander on refactoring doc.sitecore.net, hopefully I can find it on Google Hangout.

SUGCON was a great experience and It has given me a whole lot of ideas and things to look into for current and future Sitecore projects. Thanks to the Sitecore Community and the sponsors for putting on the event.

My only regret is not having chance to chat to any of the MVPs who have been so helpful on Slack and on their blogs, but I’ll definitely be back next year so I’ll buy you a beer or two then instead.

Till next time.

IMG_5878

My thoughts on SUGCON 2016 – Day 1

SUGCON Venue

I was lucky enough to arrive at my very first SUGCON a day early and see at bit of the Copenhagen. It’s beautiful, everyone is very friendly and the food and beer is impeccable, if you get chance to go then you definitely should.

 

Opening Keynote

Day 1 of SUGCON kicked off on Monday afternoon with an opening Keynote from Lars Nielsen (Sitecore Co-Founder & Chief Development Officer). This was to prove one of the most intriguing presentations of the conference as Lars revealed a number of new features coming in Sitecore 8.2.

8.2

One bug-bear for a lot of Sitecore clients is the upgrade process, Lars assured us that in 8.2 (using the Express Migration Tool) this is going to be much easier and won’t involve upgrading in multiple steps (as is currently the case) and that is should be possible to move from 6.5 > 8.2 in one automated step. This is great news for those running 6.5 and 7 solutions as it should make the process a whole lot easier and quicker.

Lars then followed this with an overview of 8.3 features (sorry It’s blury):

8.3

The most interesting for me (and clients I work with) was the Webforms for Marketers is going to be removed in 8.3 and replaced by an out of the box module, which will look something like this:

forms

This looks a whole lot better than WFFM which as most Sitecore developers know can be a pain to customise and is pretty clunky to use.

This was reflected by the attendees as there was a round of applause from the room when this was announced. It will work in the experience editor allowing in-place editing – just like other Sitecore components, so content editors should find the experience simpler and more intuitive. There will be integrations with automation plans too:

forms2

In summary these are the Roadmap themes:

roadmap

This was a great start with lots of useful info about the future releases coming up!.

 

Serialise all the things with Unicorn

Next up was Kam Figy, an MVP at Connective DX and the lead developer of Unicorn – a tool for serializing your Sitecore Items to disk so you can check them in to source control alongside your code.

unicorn

Kam ran through a demo of Unicorn 3 which I’ve already used, but it was nice to see a full demo and find out more information about other options the we could potentially make use of.

He then showed us a project he’d done for the Sitecore hack-a-thon, which allows unicorn to sync Roles and Users as well as Items. This could be useful for future projects and is now available in Unicorn 3.2 (https://www.nuget.org/packages/Unicorn).

sync

Kam’s talk was entertaining and he managed to handle the slightly awkward Hedgehog vs Unicorn questions afterwards pretty well too :-).

 

After a short break the talks split off into different tracks for the rest of the afternoon and I went with these 3:
Atomic Design Talk by Tim Braga, Design Patterns by Mike Reynolds and then Building Large Scale Sitecore solutions by Mike Edwards.

Atom Design to the MAX

Tim talked through the different approaches to building Sitecore Sites and then explained why instead of just going down to component level (as most Sitecore developers do) his team now breaking every element of a component down further into Atoms and making these separate renderings.

atomic

This allows for more control over functionality, layout and personalisation/testing on a more granular level – e.g. A/B testing on just a single button. Below is an example of this for the Hero that Collette created:

hero

There were however some performance issues found though with Experience Editor and it does add time for development, testing and content entry. Tim went over the pros and cons and what they have carried out to try and work-around some of them:

proscons

I like some of the concepts but I’m not yet convinced this is the way to go for most Sitecore builds, unless there really is call for this level of control.

 

Design Patterns

I wasn’t sure what to expect with this talk but I was a bit surprised to see it was less Sitecore focused and more around Design patterns and their usage in programming in general.

design patterns

Still it was good to see examples of their usage with Sitecore from Mike and the pros and cons of each approach.

pattern

 

Building Large Sitecore Solutions

This talk by Mike Edwards was really good. Mike gave and overview of the infrastructure and architecture of Sitecore solutions as they grow and require more CD servers and xDB provisioning.

scale

He talked about blue/green deployments and the importance of trying to have zero downtime for client sites during deployments. He also discussed load balancing strategies and the pros and cons of the different approaches.

blue-green

I’ve had first-hand experience of doing this for a few clients and it’s good to see some of the ideas we’ve used re-enforced by Mike, such as having two web databases in place so that one can be used for deployment whilst the other is live.

The architecture with xDB included looks pretty crazy but this demonstrates the number of servers and considerations involved with xDB:

xDB

After this (and a short talk by Coveo regarding their Search product) it was time to drink beer, eat food 🙂 and chat to some other Sitecore people.

There were also awards given out for the Sitecore MVPs (well done guys) and a Sitecore quiz with beer to be won.

All in all a great first day and some really informative sessions. I was really looking forward to Day 2.

Refreshing Experience (Page) Editor after using Edit Frames or Buttons

Frustratingly when editing an component in Sitecore 8 using either edit frame (or a Custom Experience Editor Button) the component datasource does not refresh, you need to click the save button afterwards to refresh the page and see your changes.

Content Editors could find this confusing, especially if they have just added some items to a multi-list (e.g a list of products) in the modal window
and the new/updated products do not show on the product listing component.

Someone on the Sitecore Slack Channel also needed to solve this issue this week which prompted me to write this up.

Google didn’t turn up any solutions so I set out to try and figure out how to make the page refresh and show the changes. After trying a couple of different approaches I settled on overriding two standard Pipelines under :

Sitecore.Shell.Applications.ContentManager.ReturnFieldEditorValues.SetValues
and
Sitecore.Shell.Applications.ContentManager.ReturnFieldEditorValues.ReturnAndClose

To get the code for these I first decompiled the Sitecore.Client dll and copied the SetValues.cs
and ReturnAndClose.cs classes. My customised versions are below, you will need to reference a number of Sitecore classes such as: Sitecore , Sitecore.Data, Sitecore.Shell.

 

SetValuesAndSave.cs:

public class SetValuesAndSave
{
public void Process( ReturnFieldEditorValuesArgs args)
{
args.Options.SaveItem = true;
foreach ( FieldInfo fieldInfo in args.FieldInfo.Values)
{
Control subControl = Context.ClientPage.FindSubControl(fieldInfo.ID);
if (subControl != null)
{
string str1;
if (subControl is IContentField)
str1 = StringUtil.GetString((subControl as IContentField ).GetValue());
else
str1 = StringUtil.GetString(ReflectionUtil .GetProperty(subControl, “Value”));
if (str1 != “__#!$No value$!#__”)
{
string str2 = fieldInfo.Type.ToLowerInvariant();
if (str2 == “rich text” || str2 == “html”)
str1 = str1.TrimEnd(‘ ‘);
foreach ( FieldDescriptor fieldDescriptor in args.Options.Fields)
{
if (fieldDescriptor.FieldID == fieldInfo.FieldID)
{
ItemUri itemUri = new ItemUri(fieldInfo.ItemID, fieldInfo.Language, fieldInfo.Version, Factory.GetDatabase(fieldDescriptor.ItemUri.DatabaseName));
if (fieldDescriptor.ItemUri == itemUri)
fieldDescriptor.Value = str1;
Item item = Factory.GetDatabase(fieldDescriptor.ItemUri.DatabaseName).GetItem(itemUri.ItemID);

// Save item as above doesn’t persist after postback
if (item != null)
{
item.Editing.BeginEdit();
item.Fields[fieldInfo.FieldID.ToString()].Value = str1;
item.Editing.EndEdit();
}
}
}
}
}
}
}

 

ReturnCloseAndRefresh.cs:

public class ReturnCloseAndRefresh
{
public void Process( ReturnFieldEditorValuesArgs args)
{
SheerResponse.SetDialogValue(args.Options.ToUrlHandle().ToHandleString());
SheerResponse.SetModified(true );
SheerResponse.CloseWindow();

//Reload the page editor after closing
SheerResponse.Eval(“window.top.location.reload();” );
}
}

 

Now you have two custom pipelines you will need to register them with a patch file like so:

<processors>
<uiReturnFieldEditorValues>
<processor type=”ScExtensions.Pipelines.SetValuesAndSave, ScExtensions”
patch:instead=”processor[@type=’Sitecore.Shell.Applications.ContentManager.ReturnFieldEditorValues.SetValues’]”/>
<processor type=”ScExtensions.Pipelines.ReturnCloseAndRefresh, ScExtensions”
patch:instead=”processor[@type=’Sitecore.Shell.Applications.ContentManager.ReturnFieldEditorValues.ReturnAndClose’]”/>
</uiReturnFieldEditorValues>
        </processors>

 

Thats it, once you’ve build and deployed your code you should find that any changes made in the field editor modal window are automatically saved for you and the page is auto-refreshed showing the updates.

One potential issue here is that by firing the refresh the content editor may loose other changes they have made to the page and not yet saved but the do get prompted about the refresh so will be aware of this.

I’d love to know of a better/easier way of doing this so feel free to let me know if you know of one.