Steps for Creating Custom Publishing Targets in Sitecore

Share:

I wanted to share some insights on creating a custom publishing target in Sitecore (refer to Screenshot 3), specifically focusing on the creation of a custom publishing target database and related configurations such as patch and connection string.

Creating a custom database publishing target in Sitecore involves several steps, including creating a new database, setting up a publishing target, and configuring Sitecore to recognize and use this new target. Here is a step-by-step guide:

STEPs:
Step 1: Add Publishing Target in Sitecore
  1. Open Sitecore Content Editor.
  2. Navigate to /sitecore/system/Publishing targets.
  3. Create a new Publishing Target:
    • Right-click on Publishing targets.
    • Select Insert -> Publishing target.
    • Enter the name preview for your publishing target.
  4. Configure the Publishing Target:
    • Select the new Preview publishing target item.
  5. In the Data section, set the Target database field to preview.

    Screenhot 1:
Step 2: Create Database by Copying Web Database
  1. Open SQL Server Management Studio (SSMS).
  2. Copy the Web Database:
    • Right-click on the Web database.
    • Select Tasks -> Copy Database....
    • Follow the wizard to create a new database. In my case I named it with sitecoredb_Preview
Step 3: Add New Connection String
  1. Open the ConnectionStrings.config file in your Sitecore instance (usually located in the App_Config folder).
  2. Add the connection string for the new database (Copy connection string of web database and rename a value of name attribute as "preview" and update database and credentials ).

    Example:
    <connectionStrings>  <add name="preview" connectionString="Data Source=(local);Initial Catalog=sitecoredb_Preview;User ID=sa;Password=SQLSERVER_PASSWORD" /> </connectionStrings>

Step 4: Add Patch Config in Include Folder
  1. Create a new patch file in the App_Config\Include folder.
  2. Name the patch file ZZZ.sitecoredb_Preview.config.
  3. Add the following XML content to the patch file to include the new database and update the value of attribute name and id of each as preview (three places). In the XML code given below we have alrady added value as preview:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
      <sitecore>
        <eventing defaultProvider="sitecore">
          <eventQueueProvider>
            <eventQueue name="preview" patch:after="eventQueue[@name='web']" type="Sitecore.Data.Eventing.$(database)EventQueue, Sitecore.Kernel">
              <param ref="dataApis/dataApi[@name='$(database)']" param1="$(name)" />
              <param hint="" ref="PropertyStoreProvider/store[@name='$(name)']" />
            </eventQueue>
          </eventQueueProvider>
        </eventing>
        <PropertyStoreProvider>
          <store name="preview" patch:after="store[@name='web']" prefix="web_secondary" getValueWithoutPrefix="true" singleInstance="true" type="Sitecore.Data.Properties.$(database)PropertyStore, Sitecore.Kernel">
            <param ref="dataApis/dataApi[@name='$(database)']" param1="$(name)" />
            <param resolve="true" type="Sitecore.Abstractions.BaseEventManager, Sitecore.Kernel" />
            <param resolve="true" type="Sitecore.Abstractions.BaseCacheManager, Sitecore.Kernel" />
          </store>
        </PropertyStoreProvider>
        <databases>
          <!-- web_secondary -->
          <database id="preview" patch:after="database[@id='web']" singleInstance="true" type="Sitecore.Data.DefaultDatabase, Sitecore.Kernel">
            <param desc="name">$(id)</param>
            <icon>Images/database_web.png</icon>
            <securityEnabled>true</securityEnabled>
            <dataProviders hint="list:AddDataProvider">
              <dataProvider type="Sitecore.Data.DataProviders.CompositeDataProvider, Sitecore.Kernel">
                <param desc="readOnlyDataProviders" hint="list">
                  <protobufItems type="Sitecore.Data.DataProviders.ReadOnly.Protobuf.ProtobufDataProvider, Sitecore.Kernel">
                    <filePaths hint="list">
                      <filePath>$(dataFolder)/items/$(id)</filePath>
                      <modulesFilePath>/sitecore modules/items/$(id)</modulesFilePath>
                    </filePaths>
                  </protobufItems>
                </param>
                <param desc="headProvider">
                  <dataProvider ref="dataProviders/main" param1="$(id)">
                    <disableGroup>publishing</disableGroup>
                    <prefetch hint="raw:AddPrefetch">
                      <sc.include file="/App_Config/Prefetch/Common.config" />
                      <sc.include file="/App_Config/Prefetch/Webdb.config" />
                    </prefetch>
                  </dataProvider>
                </param>
              </dataProvider>
            </dataProviders>
            <PropertyStore ref="PropertyStoreProvider/store[@name='$(id)']" />
            <remoteEvents.EventQueue>
              <obj ref="eventing/eventQueueProvider/eventQueue[@name='$(id)']" />
            </remoteEvents.EventQueue>
            <archives hint="raw:AddArchive">
              <archive name="archive" />
              <archive name="recyclebin" />
            </archives>
            <cacheSizes hint="setting">
              <data>100MB</data>
              <items>50MB</items>
              <paths>2500KB</paths>
              <itempaths>50MB</itempaths>
              <standardValues>2500KB</standardValues>
            </cacheSizes>
            <BlobStorage hint="raw:AddBlobStorage">
              <providers default="classic">
                <provider name="classic" type="Sitecore.Data.Blobs.ClassicSqlBlobProvider, Sitecore.Kernel">
                  <param desc="databaseName">$(id)</param>
                </provider>
              </providers>
            </BlobStorage>
          </database>
        </databases>
      </sitecore>
    </configuration>
Step 5: Copy Web and Rename as preview
  1. Navigate to the App_Data\items folder in your Sitecore instance.
  2. Copy the web folder and rename the copied folder to preview.
  3. Inside preview folder rename the file from items.web.dat to items.preview.dat
Screenshot 2:

Step 6: Restart IIS/Application Pool

Final Steps: Test and Verify
  1. Open Sitecore Content Editor.
  2. Publish content to the new Preview publishing target to ensure everything is configured correctly:
    • Select an item to publish.
    • Click Publish -> Publish Item.
    • Choose the preview publishing target and complete the publishing process.

Screenshot 3:


  1. Verify the Published Content:
    • Check the new sitecoredb_Preview database in SQL Server or from Desktop in Sitecore to ensure the content is being published correctly.
    • Access the content on your site through the configured target URL (if applicable).
By following these detailed steps, you should have a custom database publishing target set up and working in Sitecore.

Hi! I am Sartaj Husain. I am a Professional Software Developer, live in Delhi. I write blogs in my free time. I love to learn and share the knowledge with others because it is no good to try to stop knowledge from going forward. So free posts and tutorials. more..

No comments