Skip to content

Creating a Template with Standard Values

sergeyshushlyapin edited this page Nov 6, 2014 · 2 revisions
[Fact]
public void HowToCreateTemplateWithStandardValues()
{
  var templateId = new Sitecore.Data.TemplateID(Sitecore.Data.ID.NewID);

  using (Sitecore.FakeDb.Db db = new Sitecore.FakeDb.Db
    {
      // create template with field Title and standard value $name
      new Sitecore.FakeDb.DbTemplate("Sample", templateId)
      {
        { "Title", "$name" }
      }
    })
  {
    // add item based on the template to the content root
    Sitecore.Data.Items.Item contentRoot =
      db.GetItem(Sitecore.ItemIDs.ContentRoot);
    Sitecore.Data.Items.Item item = contentRoot.Add("Home", templateId);

    // the Title field is set to 'Home'
    Xunit.Assert.Equal("Home", item["Title"]);
  }
}
Clone this wiki locally