Sitecore Sloth Module 1.1 Released

santa-helperA few weeks ago I wrote about how I updated Sloth to support Items as Resource files.  I’ve now got round to releasing this package on Nuget and creating Sitecore Packages for this too in case you want to install in that way instead. I’ve updated the Github readme with all the info too.

Sloth 1.1 supports being able to enable and disable the module under the settings here: /sitecore/system/Modules/Sitecore Sloth. Please ensure you enable the module and save the item after installing version 1.1.

sloth-enabled

 

 

 

 

 

 

Installing Sloth 1.1 for Sitecore 10.1+ Via Nuget

You can install version 1.1 of Sloth via Nuget like so if using Sitecore 10.1 or above:

Install-Package FluxDigital.Foundation.Sloth -Version 1.1.0

I’ve tested installing the Nuget package for Sitecore 1.1 and if installed correctly you should see the following files:

sloth-1.1-nuget-install

 

sloth-1.1-nuget-install-2

 

 

 

 

I haven’t created a Sloth 1.1 Nuget package for Sitecore 8-10 yet but I will do so when I get a minute.

Hope this helps and your enjoying using Sloth.

Please let me know of any issues you have and I’ll try and resolve them ASAP.

Have a great Christmas everyone.

Creating a Table Component for Sitecore

So not too long ago I had a requirement to create an Table component for a client.why
Before you shoot me down, I know this is generally a bad idea as the RTE in Sitecore has in-built support for Tables and there are Rich Snippets too. However there were a number of reasons that wouldn’t work well in this scenario, read on to find out why.

But, but RTE!?

table-expeditor

 

 

 

 

 

 

 

There were some specific requirements which couldn’t be met by the RTE or Rich Snippets fully, we needed to:

  • Add some specific mark-up, classes and wrapping divs around the table (some of this was for responsive requirements).
  • Enforce Table header, body and footer rows
  • Reduce the options for cells and rows to control better what content editors can do (for consistency).
  • Be able to update the table mark-up easily in the future (so Rich Snippets wouldn’t work well here either)
  • Limit the RTE options within a cell also to control better what content editors do.

Ok so how does the Component work?

So I did a bit research and thinking about various options and I liked Ben Golden’s answer on SSE. This provided a simple solution using Sitecore’s standard item and child item architecture to structure the tables.

So this is what I went for, it looks like so in Sitecore:

table-cells

As you can see the structure is Table > Row > Cell(s) and the Table has 3 fields. More could be added easily if required in future.

There are no specific fields on the Rows but the Table has two checkboxes:
table

 

The cell template looks like so:
cell-template

You can see the rowspan and cellspan options use a list of items as their datasource. We also use a custom RTE profile for the cell text to only allow a very small amount of RTE options.

Show me the Code

The following elements were required to build the component.

Rendering

The view is pretty simple. It just loops over the rows and outputs the cells. It also works out if a header and/or footer is required and if so renders out the correct mark-up for the first/last row. We are using Glass here so this may differ a bit for some sites. Note I’ve removed the code for row and cell span to make it easier to read:

The rendering itself is just a simple Sitecore View Rendering:   table-rendering

Models

The following are the 3 models which are used by the component, again pretty simple. The models are mapped with standard Glass mapping for the fields so I’ve not included that here:

What does it look like?

All being well you should see something like this output in the page:

table-output

 

 

 

 

 

 

In experience editor you can edit the cells like so:

cell-editing

Adding Rows and Cells quickly

This all works quite nicely but it can be time consuming to add rows and columns, especially if creating large tables. So there was a requirement to automate this. So I created a custom action which works in both experience editor and content editor. It’s fairly intelligent as does things like checking to see how many cells exist for current rows when adding new ones, orders the cells and rows automatically and names them for the user too.

add-table-row

 

 

 

 

 

 

add-table-row-5

 

 

 

 

 

 

add-table-row-8

 

 

 

 

 

 

Here is the code, note you will need to update the template ids for the rows and cells if re-using this code:

This is patched in for Content Editor like so:

<sitecore>
<commands>
<command name=”webedit:ext:addtablerows” type=”MyWebsite.Commands.AddTableRows, MyWebsite”/>
</commands>
</sitecore>

It can be added to experience editor by creating an custom experience button to call the command and assigning it to the rendering.

Is this a good idea?

Inevitably there will be requests to add more and more functionality to the table component over time to support things like alignment of cell content and so forth which adds further development time and complexity to the component. However for simple tables this does work fairly well and is an option where there are complicated design requirements or content editor restrictions required for Tables.

Hopefully this is useful for those considering building a Table component and weighing up the pros and cons of doing so.

Automate Adding Experience Editor Buttons to Renderings with SPE

I had an situation last week where I needed to add a experience editor button to all components and we have 63 of them. So Instead of doing this manually I decided to see if I can do this easily with SPE.

The other thing I had to consider is that most renderings had some custom experience editor buttons already, so I needed to make sure these were maintained.

exp-editor-button

Also I only wanted to add the button if there was a datasource set as it is only relevent to components with buttons.

It turns out this wasn’t that tricky and this same script could be used to populate any multi-list field, such as auto-setting the compatible renderings:

add-exp-editor-button-spe

Show Me The Script Already

Hopefully someone else will find this useful too.

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.

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.