Friday, November 29, 2019

Installing Sitecore 9.3 with SXA and Horizon in a custom location

Installing Sitecore 9.3 - Sitecore Installation Assistant

I've seen many blogs now about installing Sitecore (9.3) with the Sitecore Installation Wizard. If this is still new to you, you might want to read this one from Robbert Hock. With the official release of Sitecore 9.3 and also Horizon, more blogs appeared. If you haven't installed Horizon yet, you might want to read this post by Adam Seabridge.

By default Sitecore (the simple developer version) will install everything in [systemDrive]:\inetpub\wwwroot. But what if you don't want that?

Installing in a custom root path

Installing Sitecore itself in another location has been made fairly easy. Open the setup.exe.config that comes with SIA and add this parameter to the XPSingle template (if that is what you are installing):
<template name="XPSingle" path=".\XP0-SingleDeveloper.json">
  ...
  <parameter name="SitePhysicalRoot" value="[your-path]" />
</template>
That will make sure that Sitecore, xConnect and the IdentityServer are installed on "your path".

SXA

You can also install SXA with the Sitecore Installation Assistant. SIA has a screen for optional modules that includes SXA (actually it includes only SXA at the moment). If you check that, SXA will be installed.

Or not.. if you have set the SitePhysicalRoot, the install will fail
Apparently the json files for SXA were not adjusted to be able to use another physical root. The simple solution is to change the path in SXA-XP0.json:
"Site.PhysicalPath": "[joinpath(environment('SystemDrive'), '...', '...', 'wwwroot', parameter('SiteName'))]"

A more advanced solution would be to change all used sxa json files to pass the parameter into the sxa-XP0.json:
  • Add the parameter in the sxa-XP0.json
  • Replace the variable in sxa-XP0.json with a check for the parameter (copy the code from identityserver.json)
  • Add the parameters in SXA-SingleDeveloper.json just as it was done in XP0.SingleDeveloper.json (you will have 2 - the actual parameter and a reference with SXA: prefix)
  • Add the parameter in setup.exe.config in the SXAXPSingle template section just as it was done in the XPSingle template

Horizon

Sitecore 9.3 comes with the first version of Horizon - which you need to install separately and without SIA (described by Adam as mentioned in the intro). But again - what if your Sitecore is not installed in the default location? And what if you want Horizon to install next to that Sitecore? 

It seems that some things were prepared to make this work, but definitely not all. So I'll guide you through the quick fix to get Horizon on your desired path:

Configs/sitecore-ah.json
  • Find AuthoringHost.Site.PhysicalPath (line 40) and adjust the path as needed 
Configs/sitecore-cm.json
  • Change the parameter Site.PhysicalPath (line 15) to SitePhysicalPath
  • Also make this change to the parameter name in the definition of the Site.PhysicalPath variable (line 46) - the variable can keep the "." in the name
parameters.ps1
  • Set SitecoreIdentityServerPhysicalPath (this is in the file by default)
  • Add SitePhysicalPath = "your-cm-path" to the $sitecoreCM parameters
  • In $sitecoreIS, set the AuthoringHostPhysicalPath to the path you desire for the authoring host (Horizon) - note that this is by default set to c:\inetpub\wwwroot
  • Fill in all other parameters as mentioned in the install guide

That worked for me. There is probably a better solution for the ah.json part to use parameters, but this should get you going at least.

Happy installing!


Tuesday, November 26, 2019

This was 2019 - Sitecore Symposium & such

2019 - Sitecore Symposium

Sitecore Symposium is done – and so is 2019. Well, almost. Winter is coming.. and so is Sitecore 9.3. Almost.

You probably already read many posts about the big new announcements – Sitecore SaaS and Sitecore AI. If not, you should. Or you can also watch the videos of the keynotes now.

Horizon - the editing experience

It is exciting news. The experience for customers will change with Horizon as the new editing environment.
This project was announced a few symposia ago – we saw a first somewhat working demo last year and with Sitecore 9.3 we should will see the first version. As this first version will be limited -and also optional- the currently known editors (content and experience) will remain in place until Horizon is mature enough to take their place and become the full-fledged new experience. Probably combined with Content Hub, as Sitecore is making good progress with the integration of the StyleLabs SaaS platform that was acquired last year.


New development experience

But not only the editors should be excited. Also developers working with Sitecore will see new stuff in the future versions as this SaaS platform is bound to change things.

We will see more .net core and other enhancements to make our development experience evolve (in a good direction – I think).


Sympo and more...

But Symposium was so much more. We had a Magic-al basketball player with one of the most remarkable keynote sessions of the last symposia – I’m sure lots of people will remember this for a long time. It doesn’t happen a lot that you witness a Mexican wave going through a Sitecore crowd just because the speaker is walking between the audience (and everyone wants a picture).  And he had something interesting to say too:

SXA

Which brings me to a personal highlight of this years Symposium: I was able to give an enhanced session on SXA – using it and going beyond the out-of-the-box stuff. I did spend a lot of time preparing it as during the preparation Sitecore decided to give me the 9.3 preview (one of the benefits of being mvp), including some new fancy (Scriban) features which I had to include (and customize) in the presentation. But it was fun, and I think it went well - so I might do that again next year. Or maybe I’ll try SugCon, or a non-Belux user group, … we’ll see what 2020 brings us.

Breakouts

Symposium is not only keynotes with big speakers and/or announcements. There are lots of breakout sessions and I must say the overall quality of those was rather high this year. There was mine of course (😊), and my co-Reffer Bart’s on Forms (😊) but I enjoyed several others as well. Matthew Dubbs (Test Specialist @ Sitecore) did a very good job on stage and thought me a few tips on performance testing (remember the robot detection and analytics cookie).  SXA Blues Brothers Mark & Adam showed us a few new things in SXA 9.3 (Scriban …) and the Corey/Gary duo managed to introduce us to Blazor and show that headless is not necessarily Javascript (well done guys – can’t be easy doing this so remote).  Alexey Vaschenko had the honor of presenting Horizon and especially how we (developers) will be able to extend it with Sitecore Host plugins  - can’t wait to try that!

Sorry for those who I forgot to mention – so many sessions, I couldn’t attend all of them…  Some speakers already shared their presentations – and Sitecore just released all slides as well – so you might want to check those (or attend a local user group session as some presentations are repeated there).

Luckily for us, in between five exhausting days of Symposium sessions and Sitecore MVP sessions, we also found some time to

check the local wildlife

visit Harry Potter

play ball with some fellow MVP's

enjoy an Orlando Magic victory with my colleagues from The Reference

do some #HedgieHunt - even though we had so little time, and speakers didn't get one   - my hedgie collection has a new addition

And most importantly meet, greet, talk, drink and mingle with other attendees and share ideas and silly small talk with Sitecore community members.

If this all sounds like music to your ears, get ready to join the 2020 Symposium in Chicago πŸ˜‰

2019

Yes, 2019 was a remarkable year.  It started with a renewed MVP title and the release of a new website for Fluxys – an exciting SXA project we had been working on (and still are).

Together with a few colleagues I decided to get (back) on my bike and climb the legendary Mont Ventoux. It took a lot of training, sweat, painful knees and a variety of swear-words. Especially during the hilly trainings, I wondered what the hell I was doing. But in June I was on top of the mountain, and it was such a monstrous experience… I’ll probably do that again in 2020.


The sad news was that I had to say goodbye to my good pet/friend Jef - after 11 years he got hit by a car (actually his 2nd time, but this time fatal).
Together with all my other cats he perked up my Symposium presentation though. And the house is filled with a few kittens now.


And so 2019 is almost over, MVP application is done...  just one more Sitecore upgrade to finish, one more Sitecore presentation to give, a Sugcon call-for-papers to answer,  and then make sure that tree is cat-friendly.




We see 2020 at the Horizon..  Get ready for a tremendous year!

Symposium 2020

Wednesday, November 6, 2019

SXA beyond the box - Sitecore Symposium 2019

SXA beyond the box

November 6th 2019. Orlando.

I had the honor and pleasure to present a session on the Sitecore Symposium 2019 in Orlando. Spreading knowledge on one of my favorite work-related topics: Sitecore SXA.

As we already had sessions explaining the basics of SXA I thought it might be time to have a session that went one step further. So I proposed the idea, got selected, and started creating the presentation.

The presentation is using user stories from the Fluxys project that I worked on recently to show some examples on how you can tweak SXA to your needs. We start by explaining the basic out-of-the-box options to customize renderings and continue towards more advanced examples. The presentation stays vague about all the code details but those are covered in blogs posts.

As a nice extra, I managed to show how to extend one of the very new features that come with SXA 9.3: Scriban variants.

This post includes the presentation and an overview of the mentioned blog post and documentation articles.

The presentation




Sources


The Sitecore community



Custom SXA Scriban extensions

Sitecore - SXA & Scriban


As explaining in the what's new post on SXA 9.3 one of the major new features in the Sitecore Experience Accelerator version 9.3 is the rendering variant with a Scriban template.

Sitecore's SXA team provided a whole set of extensions that will help you get almost anything done. And if that is not the case, you can easily write your own extension and that is what I will show you here.

We'll create a custom function that can optionally utilize the Sitecore context and an extension function to call on items in Scriban.

Custom Scriban context function

A context function can perform any logic based on the parameters it receives using the Sitecore context if needed. Let's see a simple example:

Code

using Scriban.Runtime;
using Sitecore.XA.Foundation.Abstractions;
using Sitecore.XA.Foundation.Scriban.Pipelines.GenerateScribanContext;

public class ScribanMeow : IGenerateScribanContextProcessor
{
    private readonly IContext context;

    public ScribanMeow(IContext context)
    {
        this.context = context;
    }

    public void Process(GenerateScribanContextPipelineArgs args)
    {
        var meow = new MeowIt(Meow);
        args.GlobalScriptObject.Import("sc_meow", (Delegate)meow);
    }

    public string Meow(string key)
    {
        return key + " Miauw";
    }

    private delegate string MeowIt(string key);
}
We create a class implementing the IGenerateScribanContextProcessor. We inject the IContext in our constructor. In this example we're not using it, but this shows that you can if you need to. The Process function will attach our delegate to the Scriban function that we can name as we want (in this example the name is "sc_meow").

The delegate can have parameters as needed - here just a string but have more and/or other object types. The implementation of the delegate contains the logic you want performed by the function (in this example case we are just meowing the given text).

Config

<sitecore>
  <pipelines>
    <generateScribanContext>
      <processor type="Sxa93.ScribanMeow, Sxa93" resolve="true" />
    </generateScribanContext>
  </pipelines>
</sitecore>
We are placing our processor in the generateScribanContext pipeline - don't forget to add the resolve element if you want the context to get resolved in your constructor.

Usage

Once this is all done, we can use our function by calling it in a Scriban template. In our example that would be like {{ sc_meow "Key" }}.



Custom Scriban item member

An item member for Scriban is like an extension method on the Item class in C#. It's a function that gets an item and returns a value based on some logic.

Code

using Sitecore.XA.Foundation.Abstractions;
using Sitecore.XA.Foundation.Scriban.Pipelines.GetScribanItemMembers;

public class GetUpdated : GetScribanItemMember
{
    private readonly IContext context;

    protected override string MemberName => "updated";

    public GetUpdated(IContext context)
    {
        this.context = context;
    }

    protected override void Resolve(GetScribanItemMembersPipelineArgs args)
    {
        if (args.Mode == MemberMode.Name)
            args.Members.Add(MemberName);
        else
            args.MemberValue = (object) args.Item.Statistics.Updated;
    }
}
We create a class inheriting from GetScribanItemMember. We inject the IContext in our constructor. In this example we're not using it, but this shows that you can if you need to. We override the MemberName to the name we want for our extension (in this example "updated") and implement the abstract Resolve function. In this function we can place our logic - anything we want to get some output (in this example we return the updated date from the item statistics).

Config

<sitecore>
  <pipelines>
    <getScribanItemMembers>
      <processor type="Sxa93.GetUpdated, Sxa93" resolve="true" />
    </getScribanItemMembers>
  </pipelines>
</sitecore>
We are placing our class in the getScribanItemMembers pipeline - don't forget to add the resolve element if you want the context to get resolved in your constructor.

Usage

Once this is all done, we can use our item member by calling it in a Scriban template on an item. In our example that would be like {{ i_item.updated }} or {{ i_page.updated }} (or any other item object).


Conclusion

Sitecore has provided many useful extension inside SXA already, but if you do need to extend it you can. It's actually not that much work and very flexible.  Enjoy!


What's new in Sitecore SXA 9.3 - Scriban

SXA 9.3

ScribanSXA 9.3 is the successor of 1.9 - they took over the version number of Sitecore. As usual, a few new features are released - like the Aggregated Facet Filter and Facets Summary components.  One of the most eye-catching newbies however is the introduction of Scriban.

Scriban

Scriban is a fast, powerful, safe and lightweight text templating language and engine. It is introduced in the rendering variant system, so now you can add a Scriban template there.  The SXA team released a bunch of extension to Scriban to help us. We can now use Sitecore functions and objects inside a Scriban template.

Scriban SXA
All those extensions are documented by Sitecore itself, so I'm not going to repeat that information. But let's have a look at what we can do with this templating engine based upon a few issues I had before that seems to have an easier solution now. Just to have a few examples...

Examples

Data attributes

As described on https://ggullentops.blogspot.com/2018/10/using-tokens-in-sitecore-sxa-variant.html I had an issue to add classes to variants based upon a droplist field.
By using the Scriban variant it seems we can solve this a lot easier:
<div class="{{ sc_follow i_item "Color" | sc_raw "Title" }}"> ... </div>
What are we doing here? We use:
  1. sc_follow to get a target item in the Color field of i_item
  2. i_item to get the current context item (and pass it to sc_follow)
  3. | to pass this item to the next function
  4. sc_raw because to get the raw value of the Title field
Note that in "normal" situations you could use sc_field to get the value of a field - making it editable in the experience editor. But exactly that benefit makes it an issue here and an editable field inside a class parameter actually broke my experience editor. But it's good to have all options open.

And - we can achieve the same outcome with the short notation:
{{ i_item.Color.Title.raw }}

External data

On https://ggullentops.blogspot.com/2019/03/external-model-data-SXA-variant-Sitecore.html I wrote about showing external data with SXA. I mentioned the Model variant item which still exists and we have a Model Iterator variant now as well (since 1.9). This variant will iterate over your external data (with max and skip parameters). With the introduction of the processSearchItems pipeline in 1.9 (adding an object to your search results) this might become even more important.
Focusing on Scriban here, there is also a way to access that information in the Scriban templates using the o_model context object.

Translations - Dictionary

As we were facing text values in our variants (using the "Text" variant) and we did not want our editors to have to edit/translate those texts there, we wrote a custom variant definition to solve this issue. That solution is still valid, but there is an alternative now.  When you create a new site with SXA in 9.3 you will see a new item in your site root:
SXA Dictionary
The (display) name of the item should be "Dictionary - SITENAME".  This is the root item for the new per site Dictionary that was introduced. You can create dictionary entries (and folders) here, just as you can underneath the /system/Dictionary that is already known. That system dictionary is a fallback in case the key is not found in the site dictionary. You can also define a first level fallback dictionary from another site in the instance (to be able to share dictionary entries across multiple sites).

To get a value from this Dictionary inside your variant, you can call the sc_translate function in a Scriban template (pass the key as parameter).

sc_execute

SXA provided a lot of extensions that are very useful and well described - but I want to dive just a little deeper into one: sc_execute. The reason is that this one gives immense opportunities. The function executes a rendering variant field located in the Sitecore tree beneath the Scriban template.

When I got introduced to Scriban & SXA 9.3 I got the example of a responsive image. There is not (yet) a way to show those inside the template, so you could use sc_execute to get them inside the template. That nice.. but we could take it a step further. We also have the Component variant - since v1.8.

When we combine both we can create Scriban templates that contain other variants that actually render other components. Maybe even add a little rules engine sauce to it, and we have a tremendous cocktail that will blow your mind. 

Just to show we can really do a lot with this. A challenge might be to find a good balance with the templates to keep it all maintainable. 

Custom

We can also create our own Scriban extensions - that will be the next blog post.



As a side note.. if you have used NVelocity in your current solution :
Breaking change
NVelocity was removed from the Sitecore system.
Variants based on NVelocity will no longer work.