0 Comments

Best-WordPress-Search-Plugins-shutterstock_204851350

Sitecore SXA search features are really flexible and everything is content manageable.  While SXA search will often meet the client search requirements, there are some limitations with the out-of-box implementation i.e. the rendering template is hard-coded in the JavaScript, which can present difficulties to when the front-end developers want to work with these. 

Therefore, we want to extend the search results rendering so as to provide front-end flexibility, allowing for changing the mark-up, and also make sure the results mark-up is scalable and re-usable.

If you are already familiar with the SXA search result rendering, please feel free to skip the next paragraph.

 

How does SXA search result rendering work?

Search results rendering is one of the SXA search components, it’s utilizing the global scope for sharing the settings between each of the search components i.e. search box, search filter, load more button etc.. After the initial load of a page, the search results rendering will make an Ajax call to the search service API by passing the search scope and query.  Once it gets the results from server,  it will then render them on the page with the pre-defined template.  This is how the out-of-box search results rendering work. The approach is good, as it modularizes the feature into small individual features i.e. pagination, search box, filter etc., which has great maintainability and reusability.

 

Custom search results rendering

The custom search results rendering described below is built on top of the out-of-box search results rendering,but adds some enhancements.

We are going to:

  • Move the template into cshtml view (New)
  • Allowing randomly order (New)
  • Server side return results (New)
  • Enable experience editor for the result items (New)
  • Use variants for search results
  • Make use of the global scope

 

We are going to do this, using the following steps:

Step One –Create SXA rendering controller

As when creating other custom SXA controller, you will need to create a custom search results controller.  If you are unsure how to a custom custom rendering, please refer to my previous post here.

Step Two–Create custom search results repository

In order to use the variant for rendering the search results, the custom repository needs to inherit from VariantsRepository, which is the Sitecore.XA.Foundation.RenderingVariants.Repositorie namespace.

Also, we will need to inject IScopeService for utilizing the global scope in the custom repository constructor as shown below.

public CustomRepository(IVariantsRepository variantsRepository, IScopeService scopeService)
    {
        this.VariantsRepository = variantsRepository;
        this.ScopeService = scopeService;
    }

Next we need to create a custom method for retrieving the results.

public IEnumerable<ContentPage> GetItems()
        {
            var searchService = ServiceLocator.Current.Resolve<ISearchService>();

            string indexName;

            var query = searchService.GetQuery("", this.JsonDataPropertiesObject.S, this.JsonDataPropertiesObject.L, null, out indexName);

            …
        }

Step Three–Create custom search results View

<div @Html.Sxa().Component("custom-search-results", Model.Attributes)>
    <div class="component-content">
        @if (!Model.ChildrenItems.Any())
        {
            return;
        }

        <ul class="search-result-list">
            @foreach (var contentPage in Model.ChildrenItems)
            {
                <li>
                    @foreach (var variantField in Model.VariantFields)
                    {
                        @Html.RenderingVariants().RenderVariant(variantField, contentPage.GetItem(), Model.RenderingWebEditingParams)
                    }
                </li>
            }
        </ul>
        <div class="search-result-overlay"></div>
    </div>
</div>

This is what it looked like in Experience Editor, content editor can see the search results.

image

And all the settings are CMS-configurable

image

Hope you enjoyed the post and found it’s useful.

0 Comments

image

Sitecore 9 has been just released recently and one of the biggest changes is that Lucence is no longer the default search index provider.  Sitecore 9 still supports Solr, Lucene, and Azure search as providers. However,  if you want to use a search index that work in both Analytics and contentSearch, Solr is the best option.

The article below is about to provide a step-by-step guideline, so that you can quickly spin up Sitecore 9 instance locally.

The prerequisites for Sitecore 9 includes SQL 2016, IIS 8.5+ and Solr etc. By default, Sitecore XP is secure, therefore it requires SSL enabled for Solr.

Let’s start with installing Solr with SSL enabled

image

 

Step one – Download and Install Solr

You can download from here. The Solr version is 6.6.2 (as there is a bug in Sitecore 6.6.1 as mentioned here).

Step two – generate trusted self signed certificate

Thanks to Kam Figy, who create an easy to use powershell script for automating the complete setup process of adding SSL to Solr with a self-signed certificate, and trusting that self-signed certificate. You can get the script here. Save the solrssl.ps1 onto your local. You can also find the official instruction for enabling SSL on Solr here.

In order to generate a self-signed certificate and a kay, keytool needs to be installed. If you have Java runtime environment installed, you can find the keytool under the bin folder of java installation folder.

image

Before you run the script, it’s assumed that you  have the keytool utility on your PATH system environment variable. You should be see the successful message, once the certificate has been generated and added into CA.

 image

Don’t forget to uncomment in bin/solr.in.cmd file, before restarting solr server.

SOLR_SSL_KEY_STORE=etc/solr-ssl.keystore.jks
SOLR_SSL_KEY_STORE_PASSWORD=secret
SOLR_SSL_TRUST_STORE=etc/solr-ssl.keystore.jks
SOLR_SSL_TRUST_STORE_PASSWORD=secret

After you restarted the Solr, you should be able to run Solr on HTTPs protocol as shown in the screenshot below.

image

Okay, let’s kick off installing Sitecore

Step one – download Sitecore 9 package

You can download the package here. The package used for this article is the XP single package - (Packages for XP single (XP) instance configuration. Sitecore 9.0.0 rev. 171002 (WDP XP0 packages).zip).

 

Unzip the package, there are three packages included in the zip. 

image

 

Unzip the “XP0 Configuration files rev.171002.zip”, in which it contains the environment configuration files (XPo topologies).

  • sitecore-solr.json
  • xconnect-solr.json
  • xconnect-createcert.json (for developer environments)
  • sitecore-XP0.json
  • xconnect-xp0.json

Step Two – Install Sitecore Install Framework

Sitecore provides the Sitecore installation framework module, a Microsoft PowerShell module that supports local and remote installations of Sitecore, and it’s fully extensible.

Once you installed the Sitecore Fundamentals and SitecoreInstallFramework module. You can then use the PowerShell script below for installing Sitecore (Thanks to the community who created the script, it's really handy).

After the script successfully run, you should be able to see:

  • Databases

image

  • Two sites

image

Congras! Your Sitecore 9 has been successfully installed.

image

0 Comments

Recently, I’m having an issue with SXA as summarized below.  It took me quite a while for investigating and thanks to Sitecore support, it has been resolved. Therefore, I think it’s better to share it, as others may have the same issue.

Apparently it’s a bug and to track the future status of the bug report, you can use the reference number 95437

Here is the issue:

If the link field is used to wrap other fields as an example below, after user insert an link the image will disappear.

@Html.Sitecore().BeginField("Link")
  @Html.Sitecore().Field("Header Image")
@Html.Sitecore().EndField()

 

In order to get ride of the issue, you can render links with child images like:

@Html.Sitecore().BeginField("Link",new {haschildren=true})
  @Html.Sitecore().Field("Header Image")
@Html.Sitecore().EndField()

0 Comments

A few days ago, a colleague asked me about why he couldn’t access the page with preview mode, and I realized that when he was previewing the page, by default Sitecore is using the anonymous user account.  It also described here .   Apparently the bug has been resolved in Sitecore 7.2+  and to resolve this issue the new settings “Preview.AsAnonymous” has been introduced, the default value is true:

<setting name="Preview.AsAnonymous" value="true" />

So, if the value is true, Sitecore uses the Anonymous user when one previews an item, otherwise, Sitecore uses the current user account.

1 Comments
  •   Posted in: 
  • SXA

Since Sitecore releasedSitecore Experience Accelerator, there has been has a lot of discussions around why businesses that currently use Sitecore, would need SXA, and how SXA can speed up the development process. In my previous post I talked about how to create a custom SXA component. In this post, I’m going to share my experience with building a website using Sitecore SXA.

 

why SXA is good

SXA allows for the designers, UX and UI teams to work with the developers

In the traditional process, wireframe, design, front-end and back-end are working in sequence as shown in below diagram.

 

image

However, SXA gives the possibility for UX, Design, front-end and back-end to work in parallel.

image

 

SXA force best practice principles

As mentioned above, Sitecore SXA was built with Sitecore Helix framework in mind.  Developer can extend and customise the SXA features, however,  the same framework and principles have to be followed.

 

Reusable components

You may be thinking , but I can create component in traditional Sitecore solution and make it reusable already!  Why call out SXA?  This can be best answered with an example.

The below is a design example, and I believe as Sitecore developers, we will all agree that the circled widget is likely to be a rendering with a data source applied?

image

 

However, this would not be the approach you would talk with SXA! In SXA we define an individual column as a component.  According to the design, we will repeat the same component three times. Sitecore SXA has pre-built renderings(component) which can help us understand the principles and which we can utilise; These can be found here

In this example, the rendering we will want to re-use would be the Image (Reusable) rendering (component)!,  this means no custom rendering is required.  You just saved yourself some Back-end dev time, integration with front-end, and testing! 

SXA can significantly speed up your development process!

image

 

Building a website with SXA

Prepare SXA solution

Setup Sitecore solution by following Sitecore Helix framework.

Here is the sample structure

image

 

Define your renderings

As explained above,  in SXA when we are trying to define the rendering, we want to keep it small so that we can easily reuse it across the site.

The below is an example design for a quick links rendering (component).   Instead defining the whole panel as a widget/ rendering with data source,  we can use Image (Reusable) rendering and take the advantage of SXA rendering styling feature.

image

 

Here is how you can create a quick link rendering (in10 minutes).

1. Add  a container rendering

image

2. Add  an Image (Reusable) rendering into the container

image

 

Once you done this, it basically means you have a div wrapper for the image (Reusable)

<div class =”component container”>

..

[Image (Reusable) Rendering]

..

</div>

In order to make the image (Reusable) rendering have the same look and feel as per design, you may need a custom style.

Under site presentation, I created custom styles (I don’t want to mess with SXA styles).  I believe its important to keep the out of the boxes styles separate from out custom styles.  SXA also allows you to select allowed rendering per style.  In our case above, we are going to create a new style called ”Quick Links, and in “Allowed Renderings” select container rendering.

image

 

After that, you should be able to see the custom style in the Styles property window

image

Once you’ve done, I’m sure your front-end can do the magic to make it pretty as per the design.  easy right?

In some cases, you may need to create your own renderings, you can read my previous post about how to create custom rendering here.

 

Page Designs

Page design is defined in your project scope which is the number of page templates you are going to build.

 

Partial  Designs

Partial design is one of the beautiful design principles with SXA, where you would normallyhave presentation details defined (against standard values), SXA separates and moves these to site level. 

Partial design has the same concept of MVC partial views. SXA allows you to select multiple partial views for a page design.

 

image

 

Export/Import the site

Once you finish the page design, you can then export either a single page or the whole site, front-end developer can start to re-skin by creating a custom theme.

SXA stores all themes in media library. After restyling is completed, you can reimport these into Sitecore and SXA will automatically create new css and javascript accordingly in media library.

 

image

 

After successfully reimporting the site,  congratulations! you’ve done your first SXA site.

image

 

If you would like to see a live demo, please join the August Meetup of the Sydeney Sitecor User Group. Click here for RSVP.