Sitecore contact facets – Create your own facet

Brian Pedersen's Sitecore and .NET Blog

This article describes how to create a simple Sitecore facet consisting of a DateTime and a list of strings.

A contact is made up of facets. Here are all the facets Sitecore uses (you will find the facets in App_ConfigIncludeSitecore.Analytics.Model.Config):

In this example I will add a facet that consists of a date and a list of strings. I will call it “AvailablePublishers“.

This is a real-life example where I needed to store a list of publishers that were available the last time the user was online. Each publisher is just an ID (a string) and I store these as a list on the Contact:

Available Publishers Facet Available Publishers Facet

It sounds simple, and it is – but there is a lot of code involved. So hang on, lets code.

STEP 1: THE BASIC INTERFACES

The “AvailablePublishers” is a Facet, the list below consists of Elements. So I need…

View original post 387 more words

Advertisements

Sitecore: Sharing field data across languages

This is the third in a series of blog posts covering everything you should need to know for building a multilingual website in Sitecore.

Part 1 – Adding languages for a multilingual site
Part 2 – Translating text in your presentation

In the first two parts to this series I concentrated on how you can setup Sitecore to allow different language versions of content to be entered. In some instances though your content will contain fields which should remain the same across all language versions. This could be for product sku’s, dimensions of an object or possibly image fields.

To make a field share it’s values over multiple languages, in the template definition tick the shared checkbox against the field.

SharedField

It’s worth noting though that as well as making the field value the same across all languages, it will also be shared between all versions within the language.

Although the interface gives the impression that a field can be the default (versioned), unversioned, shared or unversioned and shared. The value of the unversioned checkbox actually become meaningless once shared has been ticked and there really are only 3 options; Versioned, Unversioned and Shared.

Sitecore: Translating text in your presentation

This is the second in a series of blog posts covering everything you should need to know for building a multilingual website in Sitecore.

In Part 1, I covered how to add a language to Sitecore so that content editors could create content in that language. In this post I’m going to show you how to create a dictionary in Sitecore so that hard coded text in your presentation or views can be translated into the relevant language.

Creating the dictionary

A dictionary is created within your content tree and then referenced from the <sites> section of your web.config file.

Somewhere outside of your sites home node (I like to create a settings folder for this sort of thing), create an item of type “Sitecore/templates/System/Dictionary/Dictionary Domain”. This will be the root item of your dictionary.

Under your root dictionary item you will be able to create Dictionary Groups and Dictionary Entry’s. I find a good way to organise your dictionary is to create a group for each letter of the alphabet and then sort your entry’s into each of these based on the key name.

Dictionary

A dictionary entry consists of a Key and a Phrase. The key is the value that will be referenced in code to lookup the entry, and the phrase is the translation that will be returned.

Translations for each language are created using regular language versions of content.

Dictionary Entry

Configuring the site to use the dictionary

For a site to use the dictionary you need to add a dictionaryDomain to the sites node. Below is an example of the default website site updated to use a dictionary called “My Dictionary”

      <site name="website" virtualFolder="/" physicalFolder="/" rootPath="/sitecore/content" startItem="/home" database="web" dictionaryDomain="My Dictionary" domain="extranet"
        allowDebug="true" cacheHtml="true" htmlCacheSize="50MB" registryCacheSize="0" viewStateCacheSize="0" xslCacheSize="25MB" filteredItemsCacheSize="10MB"
        enablePreview="true" enableWebEdit="true" enableDebugger="true" disableClientData="false" cacheRenderingParameters="true"
        renderingParametersCacheSize="10MB" />

Translating text in your view

Now that your dictionary has been set up you can start translating text in your views.

The following line of code will lookup the dictionary entry based on the key and return the phrase for the current context language.

@Sitecore.Globalization.Translate.Text("dictionary key")