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.

No comments:

Post a Comment