CET 7.7 – Creating items from Branch Templates with the Import tool

The Content Export Tool has for a while now featured the ability to create items from a CSV import (you can read all about that here). This worked well with regular templates, allowing users to easily simultaneously create and populate the fields of tens or hundreds (maybe thousands, never tried) of items at once. However, it was never tried with branch templates, and as it turns out, branch templates didn’t work.

What is a  branch template?

If you’re familiar with branch templates, you can skip ahead. A branch template is an item that is based off a regular template, but which has pre-made renderings and subitems included. When you create a page with a regular template, it can automatically have renderings and field values assigned to it on creation based on the Standard Values of the template. However, the renderings added in the Standard Values can only point to a pre-existing datasource or no datasource. A branch template can include subitems and have the renderings point to those subitems, and when an item is created from the branch template, all of the subitems are created as well and the renderings on the item can use those subitems as their datasource by default. This allows you to have a pre-formatted template where the content is all unique but the renderings and datasources a created automatically, so you don’t have to manually add every rendering to the page in experience editor.

Creating branch template items with the CET Import

The reason this didn’t work previously was because a branch template is different from a template item, and trying to programatically create a new item with a branch template the same way as with a regular template doesn’t work. It was a simple fix, however, once discovered, and the CET automatically detects whether a template specified in the CSV is a regular or branch template, so nothing has changed for the users. Now, there’s one more question you might have:

What if I want to pre-populate the content of my page, but the fields I need to populate are on the datasource items rather than the page template?

So, you’re using a branch template to create a page. That branch template has one field, “Title”. It also has one component, and the component’s datasource has one field, “Content”. Can you pre-populate the Content field with the CET Import process?

Well… actually no. The reason why you can’t is because the Content Export Tool only allows you to create or edit items with one import. So, if you’re creating a new item from a branch template, you’re going to be using the create option. This means that after the import creates the new item from the branch template, the datasource subitem already exists – you need to edit it, not create it. If you try to include the datasource item in your CSV (which you could do if you correctly predict the path where it is going to be created, which is easy enough), it will either 1) ignore it if you are not allowing duplicate item creation, or 2) create a duplicate item which will have the fields populated, but will not be connected to the rendering (the rendering will still be pointing to the original datasource item).

So the best thing here is to simply run an edit import after you’ve finished your create import. As an additional benefit, since the items already exist at this point, you can use the Export feature to easily generate you CSV for editing, by selecting the newly created item(s) as your starting path(s), selecting the templates of the items you wish to edit (optional), and choosing all fields you want to modify. You can read more here about how to use the Export feature to make your Import CSV easier more easily.

You can download the latest release now from Github; it will be available within the next month on the Sitecore Marketplace.

Author: ericastockwellalpert

.NET Developer and Sitecore MVP 2019-2020

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s