Tuesday, April 18, 2017

Redirects In Sitecore SXA

Again the wonderful Sitecore support comes to the rescue with details on using the Redirect functionality that is out of the box with Sitecore Experience Accelerator,  until the full documentation is complete I thought I would share this with the community. 


>> If a user goes to our site with a url  like http://sitename/en/our-exports/exporting.aspx  
>> We wish them to be redirected to a sitecore item for example http://sitename/exports 
>> How is this done using the SXA redirect item please? 

You can use the Redirect Map functionality. You need to create a redirect item under /sitecore/content/[Tenant]/[Site]/Settings/Redirects and specify the mapping between URLs:

redirect.png

Important note: the exporting item must not exist. Redirection will be performed only if Sitecore XP can't find a matching item, just before the user is redirected to a 404 page. 


If you want to redirect from existing item, you can use the method described in the article you mentioned. For example, you can insert a redirect item named OldContact, which will redirect to the /Contact page:


redirect_item.png



>> Also does it support wildcards and regex? If so how is this done? 

Redirect Maps support regular expressions. General rule for a regular expression in the redirect mapping: it must start with ^ and end with $. Here is a couple of examples:

This will redirect any request to a page under /products to /anotherpage:
1.png

This example uses tokens:
2.png

Tokens are regex expressions inside parentheses. There are two tokens in the input string above:

  • (.*) - matches any character
  • ([1-9]+) - matches any numeric sequence
These tokens are used in the output string as $1 and $2. Therefore, the request to /products/something/123 will be redirected to /anotherpage/something/123.










Thursday, April 6, 2017

Hiding Snippets in the Document Publisher - Sitecore PXM

Sitecore Print Experience Manager is super cool but sometimes you want text snippets to be hidden in the Document Publisher, so they still display in preview and render in the PDF, but the editors cant fiddle with them. 

This solution was provided by Sitecore support and works well - Enjoy 



The main idea of my approach is to extend the default P_Snippet template with an additional field which hides the entire Snippet section in the Edit Document application:


1. Navigate to the template "/sitecore/templates/Print Studio Templates/Publishing Engine/P_Snippet" in the master database.
2. Add a new Checkbox field with name "IsHidden". You can use another name, but this particular is referenced in the further JS code sample, so in case of a different name you'll have to change the code as well.
3. Make the field Unversioned and Shared.

Now you can mark any Snippet as hidden by checking the added checkbox. Further, you have to extend the function "loadSnippet" in the /sitecore/shell/client/Applications/ODG/Components/Controls/SnippetEdit.js file. Here is the sample code, I've highlighted the changes:

loadSnippet: function () {
  var item = this.get("item");
  if (item != null) {
 if (item.IsHidden == "1")
 this.SnippetAccordion.set("isVisible", false);

 this.SnippetAccordion.set("header", item.$displayName);

  }
  else {
this.Border.set("isVisible", false);
  }
  this.reloadData();
},

Please don't forget to clear your browser cache.