Wednesday, July 6, 2016

Sitecore Powershell Extension Snippet- Create Custom User Defined Template Item

As I said everything in Sitecore is indeed an Item. If you understand the way Item is represented knowing sitecore as CMS will be more easy.

Use Case: I want to cut down my time to create user defined template by 50% rather than creating it from sitecore content editor or using sitecore rocks. I used Sitecore Powershell Extension to my rescue.


In my case, there are 4 steps involved while creating a user defined template.They are as follows:-

  • Create New Item using Template Item
  • Create Standard Value Item for this new item
  • Add Base Template which is already defined.
  • Add Common Renderings across template.

The above is very specific to scenario I had in my project. Somehow I wanted to play with SPE. I tried this and it helped me save 50% of the work effort.

Go to TDS pick up any item and you will see the internal representation of field or standard field variables with key and name. Use this to set values using SPE.

Important to remember , when you want to assign or set standard field values switch on RAW values option from Tab Menu->View-> click on checkbox to enable it,

Using these raw values we can assign the predefined base template and renderings.

You can checkout the code snippet in Gist for more details.

Code Snippet 1

Sample TDS Code : Lookup Standard Field Variables
version: 1
id: {F80C735D-CB69D16F9C4}
database: master
path: /sitecore/content/v/extrassage
parent: {F90C17F3-5CB-85961DC46E1F}
name: extras-usage
master: {00000000-0000-0000-0000-000000000000}
template: {5AD9859D54E9F61485B}
templatekey: Menu Item

field: {BA3F86A2779C1B5E}
name: __Sortorder
key: __sortorder
content-length: 3

language: en
version: 1
revision: c9a8172a-0d3ea5665ed1

field: {FF1A9AB0-84B35A2676}
name: Title
key: title
content-length: 19

Hope this is helpful.
Post a Comment