Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Developer Primer - Sitecore

RSS
Modified on Fri, Dec 27, 2013, 11:36 AM by Administrator Categorized as Sitecore

Overview

Sitecore is a CMS (Content Management System) based on ASP.NET and typically a SQL Server database, although Oracle is also supported. It can be highly customized via Visual Studio. (Sitecore supports Visual Studio's Web Application model, not the Website model.) Content items are created within the content hierarchy and stored in the database. In certain cases, content items will point to a file on the web server. This is the case with sublayouts, which is the Sitecore term for a web user control (ASCX file). Content is stored in one of three database: Core, Master, or Web. The actual database name is prefixed with the name of your Sitecore instance, plus "Sitecore_". Thus, if the name of your Sitecore instance (specified during installation) is "MySite", the three databases would be called MySiteSitecore_Core, MySiteSitecore_Master, and MySiteSitecore_Web. The connection strings to these databases is held in the ConnectionStrings.config file in the /App_Config folder off the website root.

  • The Core database holds all the UI and security data.
  • The Master database holds all versions of all items.
  • The Web database holds the most recent version of all items, and is typically the database the production site is based upon.

Terminology

  • Template — what another CMS might call a "content type", Sitecore calls a "template". Similar to the term "class" in OOP or a database table, a template defines the fields for an item, as well as other details.

  • Inheritance — Much like object inheritance in OOP, Data Templates can inherit from base templates. In fact, Sitecore supports multiple inheritance, where a Data Template can inherit from multiple base templates. In this way, subsets of fields can be segmented into smaller base data templates, and combined as needed. It is the developer's responsibility when using multiple inheritance to ensure that there are no field names in common among the base templates being inherited from.

  • Template Standard Values — Template Standard Values is a container on a template that holds (1) default fields values, (2) default insert options, (3) default presentation layout details, (4) workflow.

  • Insert Options — Insert Options on an item (or its template) define what other items may be created subordinate to the given item. For example, you might establish that only Product items may be created subordinate to a ProductCategory item. Insert Options can be set on an item or on Template Standard Values.

  • Item — an item is a unit of addressable content. It is created from and based upon a Template. It is similar to an "object" in OOP or a row in a database table. Although each item corresponds to a row in a database table (dbo.Items), the field values aren't directly accessible as database field values.

  • Layout — TODO

  • Sublayout and Rendering — TODO

Website Creation Roadmap

Website development typically proceeds as follows.

1. Data Templates are created for each content type. An icon for template may optionally be changed at this point to distinguish items based on this template from those based on others.

2. Template Standard Values are created for the Data Template.

3. The Template Standard Values are used to specify default field values and default insert options.

4. Components are created for the presentation layer. These take the form of either a Sublayout (which is stored internally as a .NET web user control – i.e., an ASCX file) or an Rendering (which is stored internally as an XSLT file). Note the Renderings (XSLT files) are typically used for static or less complex content, and Sublayouts (ASCX files) are used for more complex presentations.

5. Template Standard Values are bound to Presentation Layout Details. Binding can be done dynamically by the use of a Sitecore placeholder control, or statically through traditional ASP.NET markup.

Using Visual Studio

  • Sitecore supports the Web Application model, not the Website model
  • Must reference the Sitecore.Kernel.DLL and set the CopyLocal property to False.
  • To debug, attach to the w3wp.exe process, which is visible only if "Show processes in all sessions" is selected.

Key Classes and Members

General

SnippetUsage
Sitecore.Context.ItemThe item we're currently working with
LinkManager.GetItemUrl()Generates an SEO-friendly URL
LinkManager.GetDynamicUrl()Generates URLs for analytics
MediaManager.GetMediaUrl()for Media Items, where you'd have an item with a reference to another item

Sample Code to Get Items

using (new SecurityDisabler())
{
    //--- Option 1 ---
    var db = Factory.GetDatabase("master");
    var items = db.SelectItems("/sitecore/content/data[@name='yyz']");

    //--- Option 2 ---
    var item = Sitecore.Context.Item;
    var items = item.Axes.SelectItems("/data[@name='yyz']");

    if (items != null)
    {
        // do something with items
    }
}

Sample Code to Create Item

Item dataFolder = null;
TemplateItem templateItem = null;
string cUser = "";

try
{
    using (new SecurityDisabler())
    {
        var db = Factory.GetDatabase("master");
        dataFolder = db.GetItem("/sitecore/content/data");
        templateItem = db.Templates["MyTemplates/Template2"];
    }

    var newItem = dataFolder.Add("Item Name", templateItem);
    newItem.Editing.BeginEdit();
    newItem["FieldName"] = "xyz";
    newItem.Editing.EndEdit();
}
catch (Exception error)
{
    throw;
}

Getting Field Values

var item = Sitecore.Context.Item;
var fld = items.Fields["fieldName"];
if (fld != null && !string.IsNullOrEmpty(fld.Value)) 
{
    // Do something
}

Indexer returns an empty string if (1) fields value is null or (2) field doesn't exist.

Field TypeClass NameValue
(most)(varies)fld.Value
Rich Text fieldHtmlField fldfld.InnerField.Value
Checkbox fieldCheckboxField fldfld.Checked
Date fieldDateField fldfld.DateTime
HyperLink fieldLinkField fldfld.Url
Image fieldImageField fldstring imageURL = StringUtil.EnsurePrefix('/', MediaManager.GetMediaUrl(fld.MediaItem));
Name-Value ListNameValueList fld(use WebUtil for manipulation, esp. ParseUrlParameters method)
List Types: Droplink, Droptree, GroupedDroplinkReferenceField fldfld.ID is a GUID for another Sitecore item
List Types: Checklist, Multilist, Treelist, TreelistExMultilistField fldfld.GetItems() // returns array of Items

Sitecore Query and the DataSource Field Property

  • Sitecore Query is an XPath-like query syntax used for retrieving items from the content tree.
  • Sitecore Query can be used in the DataSource property of a field or in code when querying items from Sitecore.
  • When querying from code, use the Database object for absolute queries, and the Axes object for relative queries.
  • Editor controls that support Sitecore Query (in their DataSource property): Droplist, Grouped Droplist, Droplink, Grouped Droplink, Checklist, and Multilist.
  • Some editor controls use a parameterized DataSource
    • Field Types: Droptree, Treelist, and TreelistEx
    • Properties: DataSource, IncludeTemplatesForDisplay, ExcludeTemplatesForSelection, IncludeTemplatesForSelection
    • Parameters and their values are concatenated like a query string, with ampersands and equal-signs.

Page Editor Support

  • Many of the Sitecore controls are supported for editing within the Page Editor.
  • The following are not, and require use of the sc:EditFrame to enable editing within Page Editor: CheckBox, all of the List Types (Checklist, Multilist, etc.)

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.