4

8.2 U5

If I move the go live date, in publish settings, out to the future for my item. And in preview mode move the date out also. I see the content fine. I consider it the poor mans unpublished item.

But if I make the content item as unpublishable, I can't preview the item at all. I have tried creating a custom preview site config and set the Preview.DefaultSite setting.

<setting name="Preview.DefaultSite">
    <patch:attribute name="value" value="customer.preview" />
</setting>

In the logs I get the error on the preview site URL:

15096 13:08:06 ERROR Item could not be found from query string. [ID is "{13A91BDC-E4E9-4AFF-87F6-95A7D9D1E891}".]

I have reviewed all the changes from this SE question, How to preview a non publishable item.

Here is my preview site config with filterItems = false, database=master as well as the targetHostName and hostName set.

<site name="customer.preview" patch:after="site[@name='modules_website']" 
      targetHostName="customer.preview" 
      filterItems="false"
      hostName="customer.preview" 
      database="master" 
      virtualFolder="/" 
      physicalFolder="/" 
      rootPath="/sitecore/content/Customer" 
      startItem="/Home" 
      dictionaryPath="/sitecore/content/USMS/Global/Dictionary" 
      dictionaryAutoCreate="false" 
      placeholderSettingsRoot="/sitecore/layout/Placeholder Settings/Project/Customer"
      domain="usmspreview" 
      allowDebug="true" 
      cacheHtml="true" 
      htmlCacheSize="50MB" 
      registryCacheSize="0" 
      viewStateCacheSize="0" 
      xslCacheSize="25MB" 
      filteredItemsCacheSize="10MB" 
      enablePreview="true" 
      enableWebEdit="true" 
      enableDebugger="true" 
      disableClientData="false" 
      cacheRenderingParameters="true" 
      renderingParametersCacheSize="10MB" 
      loginPage="/login"
      enableWorkflow="true"
      enableItemLanguageFallback="true" />
</sites>   
2

2 Answers 2

8

It is not possible to preview an item when you change the publish restrictions and make the item (or one of it's parents) not Publishable. The logic being, from my understanding, is that you are trying to preview how an item will look to the end user once published, if you make an item unpublishable then the end user will never be able to view it.

Setting up a preview site and setting <site database="master" ...> will not work due to the same reason as above.

1. Workflow

Use Workflows. Any item which is in a non-final workflow state will not be published, but you can still preview the item as normal.

If you keep a parent item in a non-approved state then none of the child item will be published either, this is useful for creating a test folder that authors can safely play around in.

The only downside to this is you have to ensure your authors do not accidentally approve this item from the Workbox. There are ways to mitigate this, such as not giving authors write access to this item or applying a different Workflow to this item, which does not have a final state and your authors do not have read access on the workflow either. This will not work as well for regular content items scattered throughout your content tree though.

2. Preview Publish Target

You can workaround this by setting up an additional Publishing Target and setting restrictions to only publish the item to this target.

  1. Attach a new web database in SQL Server with a different name, e.g. mysite_sitecore_preview

  2. Add a new entry in /App_Config/ConnectionStrings.config for the preview database

<add name="preview" connectionString="Data Source=.;Initial Catalog=mysite_sitecore_preview;..." />
  1. Add an config entry under /sitecore/databases/database node. You can duplicate the existing entry for web:
<sitecore>
  <databases>
    <database id="preview" singleInstance="true" type="Sitecore.Data.DefaultDatabase, Sitecore.Kernel">
      <param desc="name">$(id)</param>
      <connectionStringName>$(id)</connectionStringName>
      <!-- copy rest of the config same as web -->
    </database>
  </database>
</sitecore>
  1. Add the matching index for this database. Again, you can copy the existing web entry and change the database settings preview.
<sitecore>
  <contentSearch>
    <configuration>
      <indexes>
        <index id="sitecore_preview_index" type="Sitecore.ContentSearch.SolrProvider.SolrSearchIndex, Sitecore.ContentSearch.SolrProvider">
          <param desc="name">$(id)</param>
          <param desc="preview">mysite_preview_index</param>
          <locations hint="list:AddCrawler">
            <crawler type="Sitecore.ContentSearch.SitecoreItemCrawler, Sitecore.ContentSearch">
              <Database>preview</Database>
              <Root>/sitecore</Root>
            </crawler>
          </locations>
          <!-- ... Add other properties -->
        </index>
      </indexes>
    </configuration>
  </contentSearch>
</sitecore>
  1. Optionally update the site setting to use the preview database, which will allow users to preview the pages without being logged into the CMS:
<site name="website" database="preview" ... />
  1. Finally create a new Publishing Target under /sitecore/system/Publishing targets in the Sitecore content tree. Set the Target database field to the same name of the connection string entry from (2), e.g. preview.

Preview Publishing Target

If you are using Workflow then you should also check the Preview publishing target field which will allow you to publish items even though they may not be in a final workflow state. This is useful in combination with (5) above

Publish Restrictions

You can now take advantage of this additional Publishing Target so that content is not published to the web database/production site.

Publish settings

Leave the Publishable checkbox ticked under the Item tab. Instead, under the Targets tab only check the Targets that this item should be Publishable to. If you not want publish to the live site then check the other optons, i.e. Preview. You must have at least one target checked, if both are unchecked then this setting does not apply.

Again, you can apply this restriction to a parent level folder and any children under this folder will not be published. We used this method frequently, and then users move the item to the correct location when they want to publish to live.

Preview from within the CMS will now work as expected. You can also publish to the Preview target so users who are not logged into the CMS can view these pages.

Preview Site / Live Mode

Alternatively, you can also create a preview site under a different url (e.g. preview.mysite.com) by adding another <site> entry.

If you want, you can also enable "Live Mode" on the CM so users not logged in can preview the changes without the items having to be published (to the preview target)

In all scenarios you must add an additional publish target for this method to work though.

5

This issue arises because Sitecore’s preview function is designed to simulate how the site will appear to end users after publication. If an item (or its parent) has publishing restrictions, making it "unpublishable" the system prevents the preview. From Sitecore’s perspective, if an item won’t ever be visible to the public, it shouldn’t be previewed.

Solution

If you use Sitecore version 9.3 and above, you can allow previews of unpublishable items by tweaking a configuration setting.

  • Enable the previewUnpublishableItems setting by setting it to true in the configuration file for the SXA site. You need make this change in the SXA site definition item under the Site Grouping node. This setting isn’t available as a default field in Sitecore’s Site Grouping configuration, so you will need to define it in the Other Properties field.

enter image description here

If you don't use SXA, then you can configure this setting in the site definition under the /configuration/sitecore/sites/site node in the configuration.

What Does previewUnpublishableItems Do?

It allows users to preview items that are not yet publishable. By default, this value is set to false, meaning items cannot be previewed unless they’re ready to be published. Changing it to true removes that limitation, giving content authors a way to preview draft or restricted items without impacting the live site.

For more details, Refer to this blogpost: https://sitecorewithraman.wordpress.com/2024/09/08/how-to-preview-unpublished-or-draft-items-in-sitecore/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.